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>
34 "num rows (must be greater or equal to num cols)", M,
37 "((N * (N + 1)) / 2 + (M - N) * N)",
38 ((N * (N + 1)) / 2 + (M - N) * N));
42 for (
int m = 0; m < N; ++m) {
43 y_val.row(m).head(m) = x.val().segment(pos, m);
45 y_val.coeffRef(m, m) =
exp(x.val().coeff(pos));
49 for (
int m = N; m < M; ++m) {
50 y_val.row(m) = x.val().segment(pos, N);
58 for (
int m = M - 1; m >= N; --m) {
60 x.adj().
segment(pos, N) += y.adj().row(m);
63 for (
int m = N - 1; m >= 0; --m) {
65 x.adj().coeffRef(pos) += y.adj().coeff(m, m) * y.val().coeff(m, m);
67 x.adj().segment(pos, m) += y.adj().row(m).head(m);
89template <
typename T, require_var_vector_t<T>* =
nullptr>
93 "((N * (N + 1)) / 2 + (M - N) * N)",
94 ((N * (N + 1)) / 2 + (M - N) * N));
97 for (
int n = 0; n < N; ++n) {
99 lp_val += x.val().coeff(pos);
106 for (
int n = 0; n < N; ++n) {
108 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 ...