1#ifndef STAN_MATH_FWD_CONSTRAINT_UNIT_VECTOR_CONSTRAIN_HPP
2#define STAN_MATH_FWD_CONSTRAINT_UNIT_VECTOR_CONSTRAIN_HPP
18template <
typename EigMat,
26 eig_partial squared_norm =
dot_self(y_val);
27 eig_partial
norm =
sqrt(squared_norm);
28 eig_partial inv_norm =
inv(
norm);
29 Eigen::Matrix<eig_partial, Eigen::Dynamic, Eigen::Dynamic> J
32 for (Eigen::Index m = 0; m < y_val.size(); ++m) {
33 J.coeffRef(m, m) += inv_norm;
34 for (Eigen::Index k = 0; k < y_val.size(); ++k) {
35 unit_vector_y.coeffRef(k).d_ = J.coeff(k, m);
41template <
typename EigMat,
typename T,
45 const auto& y_ref =
to_ref(y);
47 lp -= 0.5 * squared_norm;
require_t< container_type_check_base< is_eigen_col_vector, value_type_t, TypeCheck, Check... > > require_eigen_col_vector_vt
Require type satisfies is_eigen_col_vector.
require_t< container_type_check_base< is_eigen, value_type_t, TypeCheck, Check... > > require_eigen_vt
Require type satisfies is_eigen.
auto divide(T_a &&a, double d)
Returns the elementwise division of the kernel generator expression.
require_t< is_stan_scalar< std::decay_t< T > > > require_stan_scalar_t
Require type satisfies is_stan_scalar.
typename partials_type< T >::type partials_type_t
Helper alias for accessing the partial type.
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
Eigen::Matrix< value_type_t< EigMat >, EigMat::RowsAtCompileTime, EigMat::RowsAtCompileTime > tcrossprod(const EigMat &m)
fvar< T > norm(const std::complex< fvar< T > > &z)
Return the squared magnitude of the complex argument.
typename promote_scalar_type< std::decay_t< T >, std::decay_t< S > >::type promote_scalar_t
T value_of(const fvar< T > &v)
Return the value of the specified variable.
auto unit_vector_constrain(const EigMat &y)
fvar< T > sqrt(const fvar< T > &x)
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
auto dot_self(const T &a)
Returns squared norm of a vector or matrix.
fvar< T > inv(const fvar< T > &x)
typename plain_type< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...