Stan Math Library: stan/math/prim/mat/fun/unit_vector_constrain.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

unit_vector_constrain.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_UNIT_VECTOR_CONSTRAIN_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_UNIT_VECTOR_CONSTRAIN_HPP
3
4 #include <stan/math/prim/arr/err/check_nonzero_size.hpp>
5 #include <stan/math/prim/mat/err/check_vector.hpp>
6 #include <stan/math/prim/mat/fun/Eigen.hpp>
7 #include <stan/math/prim/mat/fun/dot_self.hpp>
8 #include <stan/math/prim/scal/err/check_positive.hpp>
9 #include <stan/math/prim/scal/err/check_positive_finite.hpp>
10 #include <cmath>
11
12 namespace stan {
13 namespace math {
14
23 template <typename T, int R, int C>
24 Eigen::Matrix<T, R, C>
25 unit_vector_constrain(const Eigen::Matrix<T, R, C>& y) {
26 using std::sqrt;
27 check_vector("unit_vector_constrain", "y", y);
28 check_nonzero_size("unit_vector_constrain", "y", y);
29 const T SN = dot_self(y);
30 check_positive_finite("unit_vector_constrain", "norm", SN);
31 return y / sqrt(SN);
32 }
33
43 template <typename T, int R, int C>
44 Eigen::Matrix<T, R, C>
45 unit_vector_constrain(const Eigen::Matrix<T, R, C>& y, T& lp) {
46 using std::sqrt;
47 check_vector("unit_vector_constrain", "y", y);
48 check_nonzero_size("unit_vector_constrain", "y", y);
49 const T SN = dot_self(y);
50 check_positive_finite("unit_vector_constrain", "norm", SN);
51 lp -= 0.5 * SN;
52 return y / sqrt(SN);
53 }
54
55 }
56
57 }
58
59 #endif
stan::math::sqrt
fvar< T > sqrt(const fvar< T > &x)
Definition: sqrt.hpp:15
stan::math::check_vector
bool check_vector(const char *function, const char *name, const Eigen::Matrix< T, R, C > &x)
Return true if the matrix is either a row vector or column vector.
Definition: check_vector.hpp:34
check_positive_finite.hpp
check_positive.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::dot_self
fvar< T > dot_self(const Eigen::Matrix< fvar< T >, R, C > &v)
Definition: dot_self.hpp:16
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:30
stan::math::unit_vector_constrain
Eigen::Matrix< fvar< T >, R, C > unit_vector_constrain(const Eigen::Matrix< fvar< T >, R, C > &y)
Definition: unit_vector_constrain.hpp:20
Eigen.hpp
check_vector.hpp
dot_self.hpp
check_nonzero_size.hpp
stan::math::check_positive_finite
bool check_positive_finite(const char *function, const char *name, const T_y &y)
Return true if y is positive and finite.
Definition: check_positive_finite.hpp:28

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