Automatic Differentiation
 
Loading...
Searching...
No Matches
tcrossprod.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_TCROSSPROD_HPP
2#define STAN_MATH_REV_FUN_TCROSSPROD_HPP
3
11
12namespace stan {
13namespace math {
14
23template <typename T, require_rev_matrix_t<T>* = nullptr>
24inline auto tcrossprod(const T& M) {
25 using ret_type = return_var_matrix_t<
26 Eigen::Matrix<double, T::RowsAtCompileTime, T::RowsAtCompileTime>, T>;
27 arena_t<T> arena_M = M;
28 arena_t<ret_type> res = arena_M.val_op() * arena_M.val_op().transpose();
29
30 if (likely(M.size() > 0)) {
31 reverse_pass_callback([res, arena_M]() mutable {
32 arena_M.adj()
33 += (res.adj_op() + res.adj_op().transpose()) * arena_M.val_op();
34 });
35 }
36
37 return ret_type(res);
38}
39
40} // namespace math
41} // namespace stan
42#endif
#define likely(x)
Eigen::Matrix< value_type_t< EigMat >, EigMat::RowsAtCompileTime, EigMat::RowsAtCompileTime > tcrossprod(const EigMat &m)
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
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 ...