Stan Math Library  2.10.0
reverse mode automatic differentiation
columns_dot_product.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_MAT_FUN_COLUMNS_DOT_PRODUCT_HPP
2 #define STAN_MATH_FWD_MAT_FUN_COLUMNS_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>, 1, C1>
18  columns_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("columns_dot_product",
21  "v1", v1,
22  "v2", v2);
23  Eigen::Matrix<fvar<T>, 1, C1> ret(1, v1.cols());
24  for (size_type j = 0; j < v1.cols(); ++j) {
25  Eigen::Matrix<fvar<T>, R1, C1> ccol1 = v1.col(j);
26  Eigen::Matrix<fvar<T>, R2, C2> ccol2 = v2.col(j);
27  ret(0, j) = dot_product(ccol1, ccol2);
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>, 1, C1>
35  columns_dot_product(const Eigen::Matrix<fvar<T>, R1, C1>& v1,
36  const Eigen::Matrix<double, R2, C2>& v2) {
37  stan::math::check_matching_dims("columns_dot_product",
38  "v1", v1,
39  "v2", v2);
40  Eigen::Matrix<fvar<T>, 1, C1> ret(1, v1.cols());
41  for (size_type j = 0; j < v1.cols(); ++j) {
42  Eigen::Matrix<fvar<T>, R1, C1> ccol1 = v1.col(j);
43  Eigen::Matrix<double, R2, C2> ccol = v2.col(j);
44  ret(0, j) = dot_product(ccol1, ccol);
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>, 1, C1>
52  columns_dot_product(const Eigen::Matrix<double, R1, C1>& v1,
53  const Eigen::Matrix<fvar<T>, R2, C2>& v2) {
54  stan::math::check_matching_dims("columns_dot_product",
55  "v1", v1,
56  "v2", v2);
57  Eigen::Matrix<fvar<T>, 1, C1> ret(1, v1.cols());
58  for (size_type j = 0; j < v1.cols(); ++j) {
59  Eigen::Matrix<double, R1, C1> ccol = v1.col(j);
60  Eigen::Matrix<fvar<T>, R2, C2> ccol2 = v2.col(j);
61  ret(0, j) = dot_product(ccol, ccol2);
62  }
63  return ret;
64  }
65  }
66 }
67 #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)
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

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