1#ifndef STAN_MATH_REV_FUN_ROWS_DOT_PRODUCT_HPP
2#define STAN_MATH_REV_FUN_ROWS_DOT_PRODUCT_HPP
30template <
typename Mat1,
typename Mat2,
31 require_all_eigen_t<Mat1, Mat2>* =
nullptr,
32 require_any_eigen_vt<is_var, Mat1, Mat2>* =
nullptr>
34 const Mat1& v1,
const Mat2& v2) {
36 Eigen::Matrix<var, Mat1::RowsAtCompileTime, 1> ret(v1.rows(), 1);
37 for (
size_type j = 0; j < v1.rows(); ++j) {
38 ret.coeffRef(j) =
dot_product(v1.row(j), v2.row(j));
60template <
typename Mat1,
typename Mat2,
67 decltype((v1.val().array() * v2.val().array()).rowwise().sum().matrix()),
75 = (arena_v1.val().array() * arena_v2.val().array()).rowwise().sum();
79 arena_v1.adj().noalias() += res.adj().asDiagonal() * arena_v2.val();
81 arena_v1.adj() += res.adj().asDiagonal() * arena_v2.val();
84 arena_v2.adj().noalias() += res.adj().asDiagonal() * arena_v1.val();
86 arena_v2.adj() += res.adj().asDiagonal() * arena_v1.val();
95 return_t res = (arena_v1.array() * arena_v2.val().array()).rowwise().sum();
99 arena_v2.adj().noalias() += res.adj().asDiagonal() * arena_v1;
101 arena_v2.adj() += res.adj().asDiagonal() * arena_v1;
110 return_t res = (arena_v1.val().array() * arena_v2.array()).rowwise().sum();
114 arena_v1.adj().noalias() += res.adj().asDiagonal() * arena_v2;
116 arena_v1.adj() += res.adj().asDiagonal() * arena_v2;
require_all_t< is_matrix< std::decay_t< Types > >... > require_all_matrix_t
Require all of the types satisfy is_matrix.
require_any_t< is_var_matrix< std::decay_t< Types > >... > require_any_var_matrix_t
Require any of the types satisfy is_var_matrix.
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
auto rows_dot_product(T_a &&a, T_b &&b)
Returns the dot product of rows of the specified matrices.
T value_of(const fvar< T > &v)
Return the value of the specified variable.
void check_matching_sizes(const char *function, const char *name1, const T_y1 &y1, const char *name2, const T_y2 &y2)
Check if two structures at the same size.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Type for sizes and indexes in an Eigen matrix with double elements.
auto dot_product(const T_a &a, const T_b &b)
Returns the dot product of the specified vectors.
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 ...
Metaprogramming struct to detect whether a given type is constant in the mathematical sense (not the ...
Check if a type is a var_value whose value_type is derived from Eigen::EigenBase