1#ifndef STAN_MATH_REV_CONSTRAINT_CHOLESKY_FACTOR_CONSTRAIN_HPP
2#define STAN_MATH_REV_CONSTRAINT_CHOLESKY_FACTOR_CONSTRAIN_HPP
29template <
typename T, require_var_vector_t<T>* =
nullptr>
33 "num rows (must be greater or equal to num cols)", M,
36 "((N * (N + 1)) / 2 + (M - N) * N)",
37 ((N * (N + 1)) / 2 + (M - N) * N));
41 for (
int m = 0; m < N; ++m) {
42 y_val.row(m).head(m) = x.val().segment(pos, m);
44 y_val.coeffRef(m, m) =
exp(x.val().coeff(pos));
48 for (
int m = N; m < M; ++m) {
49 y_val.row(m) = x.val().segment(pos, N);
57 for (
int m = M - 1; m >= N; --m) {
59 x.adj().
segment(pos, N) += y.adj().row(m);
62 for (
int m = N - 1; m >= 0; --m) {
64 x.adj().coeffRef(pos) += y.adj().coeff(m, m) * y.val().coeff(m, m);
66 x.adj().segment(pos, m) += y.adj().row(m).head(m);
88template <
typename T, require_var_vector_t<T>* =
nullptr>
92 "((N * (N + 1)) / 2 + (M - N) * N)",
93 ((N * (N + 1)) / 2 + (M - N) * N));
96 for (
int n = 0; n < N; ++n) {
98 lp_val += x.val().coeff(pos);
105 for (
int n = 0; n < N; ++n) {
107 x.adj().coeffRef(pos) += lp.adj();
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
auto segment(T_x &&x, size_t i, size_t n)
Return the specified number of elements as a row/column vector starting from the specified element - ...
void check_greater_or_equal(const char *function, const char *name, const T_y &y, const T_low &low, Idxs... idxs)
Throw an exception if y is not greater or equal than low.
Eigen::Matrix< value_type_t< T >, Eigen::Dynamic, Eigen::Dynamic > cholesky_factor_constrain(const T &x, int M, int N)
Return the Cholesky factor of the specified size read from the specified vector.
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
fvar< T > exp(const fvar< T > &x)
typename scalar_type< T >::type scalar_type_t
typename internal::arena_type_impl< std::decay_t< T > >::type arena_t
Determines a type that can be used in place of T that does any dynamic allocations on the AD stack.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...