Automatic Differentiation
 
Loading...
Searching...
No Matches
unit_vector_constrain.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_PRIM_CONSTRAINT_UNIT_VECTOR_CONSTRAIN_BLOCK_HPP
2#define STAN_MATH_OPENCL_PRIM_CONSTRAINT_UNIT_VECTOR_CONSTRAIN_BLOCK_HPP
3#ifdef STAN_OPENCL
4
7
8namespace stan {
9namespace math {
10
22template <typename T_x,
23 require_all_kernel_expressions_and_none_scalar_t<T_x>* = nullptr>
24inline auto unit_vector_constrain(T_x&& x) {
25 using std::sqrt;
26 check_nonzero_size("unit_vector_constrain", "x", x);
28 check_positive_finite("unit_vector_constrain", "norm", SN);
29 return elt_divide(x, sqrt(SN));
30}
31
44template <typename T_x,
46inline auto unit_vector_constrain(T_x&& x, double& lp) {
47 using std::sqrt;
48 check_nonzero_size("unit_vector_constrain", "x", x);
50 check_positive_finite("unit_vector_constrain", "norm", SN);
51 lp -= 0.5 * SN;
52 return elt_divide(x, sqrt(SN));
53}
54
55} // namespace math
56} // namespace stan
57#endif
58#endif
elt_divide_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > elt_divide(T_a &&a, T_b &&b)
require_all_t< is_kernel_expression_and_not_scalar< Types >... > require_all_kernel_expressions_and_none_scalar_t
Enables a template if all given types are non-scalar types that are a valid kernel generator expressi...
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
auto unit_vector_constrain(const EigMat &y)
fvar< T > sqrt(const fvar< T > &x)
Definition sqrt.hpp:18
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.
auto dot_self(const T &a)
Returns squared norm of a vector or matrix.
Definition dot_self.hpp:21
void check_positive_finite(const char *function, const char *name, const T_y &y)
Check if y is positive and finite.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...