Stan Math Library  2.9.0
reverse mode automatic differentiation
dot_product.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_DOT_PRODUCT_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_DOT_PRODUCT_HPP
3 
7 #include <vector>
8 
9 namespace stan {
10  namespace math {
11 
21  template<int R1, int C1, int R2, int C2>
22  inline double dot_product(const Eigen::Matrix<double, R1, C1>& v1,
23  const Eigen::Matrix<double, R2, C2>& v2) {
24  stan::math::check_vector("dot_product", "v1", v1);
25  stan::math::check_vector("dot_product", "v2", v2);
27  "v1", v1,
28  "v2", v2);
29  return v1.dot(v2);
30  }
37  inline double dot_product(const double* v1, const double* v2,
38  size_t length) {
39  double result = 0;
40  for (size_t i = 0; i < length; i++)
41  result += v1[i] * v2[i];
42  return result;
43  }
50  inline double dot_product(const std::vector<double>& v1,
51  const std::vector<double>& v2) {
53  "v1", v1,
54  "v2", v2);
55  return dot_product(&v1[0], &v2[0], v1.size());
56  }
57 
58  }
59 }
60 #endif
bool check_vector(const char *function, const char *name, const Eigen::Matrix< T, R, C > &x)
Return true if the matrix is either a row vector or column vector.
size_t length(const std::vector< T > &x)
Definition: length.hpp:10
bool check_matching_sizes(const char *function, const char *name1, const T_y1 &y1, const char *name2, const T_y2 &y2)
Return true if two structures at 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–2015, Stan Development Team.