Stan Math Library  2.12.0
reverse mode automatic differentiation
rows_dot_product.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_MAT_FUN_ROWS_DOT_PRODUCT_HPP
2 #define STAN_MATH_FWD_MAT_FUN_ROWS_DOT_PRODUCT_HPP
3 
9 #include <stan/math/fwd/core.hpp>
10 #include <vector>
11 
12 namespace stan {
13  namespace math {
14 
15  template<typename T, int R1, int C1, int R2, int C2>
16  inline
17  Eigen::Matrix<fvar<T>, R1, 1>
18  rows_dot_product(const Eigen::Matrix<fvar<T>, R1, C1>& v1,
19  const Eigen::Matrix<fvar<T>, R2, C2>& v2) {
20  check_matching_dims("rows_dot_product", "v1", v1, "v2", v2);
21  Eigen::Matrix<fvar<T>, R1, 1> ret(v1.rows(), 1);
22  for (size_type j = 0; j < v1.rows(); ++j) {
23  Eigen::Matrix<fvar<T>, R1, C1> crow1 = v1.row(j);
24  Eigen::Matrix<fvar<T>, R2, C2> crow2 = v2.row(j);
25  ret(j, 0) = dot_product(crow1, crow2);
26  }
27  return ret;
28  }
29 
30  template<typename T, int R1, int C1, int R2, int C2>
31  inline
32  Eigen::Matrix<fvar<T>, R1, 1>
33  rows_dot_product(const Eigen::Matrix<double, R1, C1>& v1,
34  const Eigen::Matrix<fvar<T>, R2, C2>& v2) {
35  check_matching_dims("rows_dot_product", "v1", v1, "v2", v2);
36  Eigen::Matrix<fvar<T>, R1, 1> ret(v1.rows(), 1);
37  for (size_type j = 0; j < v1.rows(); ++j) {
38  Eigen::Matrix<double, R1, C1> crow = v1.row(j);
39  Eigen::Matrix<fvar<T>, R2, C2> crow2 = v2.row(j);
40  ret(j, 0) = dot_product(crow, crow2);
41  }
42  return ret;
43  }
44 
45  template<typename T, int R1, int C1, int R2, int C2>
46  inline
47  Eigen::Matrix<fvar<T>, R1, 1>
48  rows_dot_product(const Eigen::Matrix<fvar<T>, R1, C1>& v1,
49  const Eigen::Matrix<double, R2, C2>& v2) {
50  check_matching_dims("rows_dot_product", "v1", v1, "v2", v2);
51  Eigen::Matrix<fvar<T>, R1, 1> ret(v1.rows(), 1);
52  for (size_type j = 0; j < v1.rows(); ++j) {
53  Eigen::Matrix<fvar<T>, R1, C1> crow1 = v1.row(j);
54  Eigen::Matrix<double, R2, C2> crow = v2.row(j);
55  ret(j, 0) = dot_product(crow1, crow);
56  }
57  return ret;
58  }
59 
60  }
61 }
62 #endif
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:13
bool check_matching_dims(const char *function, const char *name1, const Eigen::Matrix< T1, R1, C1 > &y1, const char *name2, const Eigen::Matrix< T2, R2, C2 > &y2)
Return true if the two matrices are of the same size.
fvar< T > dot_product(const Eigen::Matrix< fvar< T >, R1, C1 > &v1, const Eigen::Matrix< fvar< T >, R2, C2 > &v2)
Definition: dot_product.hpp:18
Eigen::Matrix< fvar< T >, R1, 1 > rows_dot_product(const Eigen::Matrix< fvar< T >, R1, C1 > &v1, const Eigen::Matrix< fvar< T >, R2, C2 > &v2)

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