Stan Math Library  2.20.0
reverse mode automatic differentiation
columns_dot_product.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_MAT_FUN_COLUMNS_DOT_PRODUCT_HPP
2 #define STAN_MATH_REV_MAT_FUN_COLUMNS_DOT_PRODUCT_HPP
3 
4 #include <stan/math/rev/meta.hpp>
7 #include <stan/math/rev/core.hpp>
10 #include <type_traits>
11 
12 namespace stan {
13 namespace math {
14 
15 template <typename T1, int R1, int C1, typename T2, int R2, int C2>
16 inline typename std::enable_if<std::is_same<T1, var>::value
17  || std::is_same<T2, var>::value,
18  Eigen::Matrix<var, 1, C1> >::type
19 columns_dot_product(const Eigen::Matrix<T1, R1, C1>& v1,
20  const Eigen::Matrix<T2, R2, C2>& v2) {
21  check_matching_sizes("dot_product", "v1", v1, "v2", v2);
22  Eigen::Matrix<var, 1, C1> ret(1, v1.cols());
23  for (size_type j = 0; j < v1.cols(); ++j) {
24  ret(j) = var(new internal::dot_product_vari<T1, T2>(v1.col(j), v2.col(j)));
25  }
26  return ret;
27 }
28 
29 } // namespace math
30 } // namespace stan
31 #endif
Eigen::Matrix< fvar< T >, 1, C1 > columns_dot_product(const Eigen::Matrix< fvar< T >, R1, C1 > &v1, const Eigen::Matrix< fvar< T >, R2, C2 > &v2)
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:33
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Type for sizes and indexes in an Eigen matrix with double e.
Definition: typedefs.hpp:11
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.

     [ Stan Home Page ] © 2011–2018, Stan Development Team.