Automatic Differentiation
 
Loading...
Searching...
No Matches
multiply_lower_tri_self_transpose.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_MULTIPLY_LOWER_TRI_SELF_TRANSPOSE_HPP
2#define STAN_MATH_REV_FUN_MULTIPLY_LOWER_TRI_SELF_TRANSPOSE_HPP
3
12
13namespace stan {
14namespace math {
15
16template <typename T, require_rev_matrix_t<T>* = nullptr>
17inline auto multiply_lower_tri_self_transpose(const T& L) {
18 using ret_type = return_var_matrix_t<T>;
19 if (L.size() == 0) {
20 return ret_type(decltype(multiply_lower_tri_self_transpose(value_of(L)))());
21 }
22
23 arena_t<T> arena_L = L;
25 = arena_L.val().template triangularView<Eigen::Lower>();
26
27 arena_t<ret_type> res = arena_L_val.template triangularView<Eigen::Lower>()
28 * arena_L_val.transpose();
29
30 reverse_pass_callback([res, arena_L, arena_L_val]() mutable {
31 arena_L.adj() += ((res.adj().transpose() + res.adj())
32 * arena_L_val.template triangularView<Eigen::Lower>())
33 .template triangularView<Eigen::Lower>();
34 });
35
36 return ret_type(res);
37}
38
39} // namespace math
40} // namespace stan
41#endif
Eigen::Matrix< value_type_t< EigMat >, EigMat::RowsAtCompileTime, EigMat::RowsAtCompileTime > multiply_lower_tri_self_transpose(const EigMat &m)
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition value_of.hpp:18
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.
std::conditional_t< is_any_var_matrix< ReturnType, Types... >::value, stan::math::var_value< stan::math::promote_scalar_t< double, plain_type_t< ReturnType > > >, stan::math::promote_scalar_t< stan::math::var_value< double >, plain_type_t< ReturnType > > > return_var_matrix_t
Given an Eigen type and several inputs, determine if a matrix should be var<Matrix> or Matrix<var>.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...