Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
dot_product.hpp
Go to the documentation of this file.
1 #ifndef __STAN__MATH__MATRIX__DOT_PRODUCT_HPP__
2 #define __STAN__MATH__MATRIX__DOT_PRODUCT_HPP__
3 
4 #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  validate_vector(v1,"dot_product");
25  validate_vector(v2,"dot_product");
26  validate_matching_sizes(v1,v2,"dot_product");
27  return v1.dot(v2);
28  }
35  inline double dot_product(const double* v1, const double* v2,
36  size_t length) {
37  double result = 0;
38  for (size_t i = 0; i < length; i++)
39  result += v1[i] * v2[i];
40  return result;
41  }
48  inline double dot_product(const std::vector<double>& v1,
49  const std::vector<double>& v2) {
50  validate_matching_sizes(v1,v2,"dot_product");
51  return dot_product(&v1[0], &v2[0], v1.size());
52  }
53 
54  }
55 }
56 #endif

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