Stan Math Library  2.8.0
reverse mode automatic differentiation
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
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  stan::math::check_matching_dims("rows_dot_product",
21  "v1", v1,
22  "v2", v2);
23  Eigen::Matrix<fvar<T>, R1, 1> ret(v1.rows(), 1);
24  for (size_type j = 0; j < v1.rows(); ++j) {
25  Eigen::Matrix<fvar<T>, R1, C1> crow1 = v1.row(j);
26  Eigen::Matrix<fvar<T>, R2, C2> crow2 = v2.row(j);
27  ret(j, 0) = dot_product(crow1, crow2);
28  }
29  return ret;
30  }
31 
32  template<typename T, int R1, int C1, int R2, int C2>
33  inline
34  Eigen::Matrix<fvar<T>, R1, 1>
35  rows_dot_product(const Eigen::Matrix<double, R1, C1>& v1,
36  const Eigen::Matrix<fvar<T>, R2, C2>& v2) {
37  stan::math::check_matching_dims("rows_dot_product",
38  "v1", v1,
39  "v2", v2);
40  Eigen::Matrix<fvar<T>, R1, 1> ret(v1.rows(), 1);
41  for (size_type j = 0; j < v1.rows(); ++j) {
42  Eigen::Matrix<double, R1, C1> crow = v1.row(j);
43  Eigen::Matrix<fvar<T>, R2, C2> crow2 = v2.row(j);
44  ret(j, 0) = dot_product(crow, crow2);
45  }
46  return ret;
47  }
48 
49  template<typename T, int R1, int C1, int R2, int C2>
50  inline
51  Eigen::Matrix<fvar<T>, R1, 1>
52  rows_dot_product(const Eigen::Matrix<fvar<T>, R1, C1>& v1,
53  const Eigen::Matrix<double, R2, C2>& v2) {
54  stan::math::check_matching_dims("rows_dot_product",
55  "v1", v1,
56  "v2", v2);
57  Eigen::Matrix<fvar<T>, R1, 1> ret(v1.rows(), 1);
58  for (size_type j = 0; j < v1.rows(); ++j) {
59  Eigen::Matrix<fvar<T>, R1, C1> crow1 = v1.row(j);
60  Eigen::Matrix<double, R2, C2> crow = v2.row(j);
61  ret(j, 0) = dot_product(crow1, crow);
62  }
63  return ret;
64  }
65  }
66 }
67 #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:20
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–2015, Stan Development Team.