Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations 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  stan::math::check_vector("dot_product(%1%)",v1,"v1",(double*)0);
25  stan::math::check_vector("dot_product(%1%)",v2,"v2",(double*)0);
26  stan::math::check_matching_sizes("dot_product(%1%)",v1,"v1",
27  v2,"v2",(double*)0);
28  return v1.dot(v2);
29  }
36  inline double dot_product(const double* v1, const double* v2,
37  size_t length) {
38  double result = 0;
39  for (size_t i = 0; i < length; i++)
40  result += v1[i] * v2[i];
41  return result;
42  }
49  inline double dot_product(const std::vector<double>& v1,
50  const std::vector<double>& v2) {
51  stan::math::check_matching_sizes("dot_product(%1%)",v1,"v1",
52  v2,"v2",(double*)0);
53  return dot_product(&v1[0], &v2[0], v1.size());
54  }
55 
56  }
57 }
58 #endif
size_t length(const T &)
Definition: traits.hpp:159
bool check_vector(const char *function, const Eigen::Matrix< T, R, C > &x, const char *name, T_result *result)
bool check_matching_sizes(const char *function, const T_y1 &y1, const char *name1, const T_y2 &y2, const char *name2, T_result *result)
double dot_product(const Eigen::Matrix< double, R1, C1 > &v1, const Eigen::Matrix< double, R2, C2 > &v2)
Returns the dot product of the specified vectors.
Definition: dot_product.hpp:22

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