Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rows_dot_product.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__FWD__MATRIX__ROWS__DOT_PRODUCT_HPP
2 #define STAN__AGRAD__FWD__MATRIX__ROWS__DOT_PRODUCT_HPP
3 
4 #include <vector>
10 #include <stan/agrad/fwd/fvar.hpp>
11 
12 
13 namespace stan {
14  namespace agrad {
15 
16  template<typename T, int R1,int C1,int R2, int C2>
17  inline
18  Eigen::Matrix<fvar<T>, R1, 1>
19  rows_dot_product(const Eigen::Matrix<fvar<T>, R1, C1>& v1,
20  const Eigen::Matrix<fvar<T>, R2, C2>& v2) {
21  stan::math::check_matching_dims("rows_dot_product(%1%)",v1,"v1",
22  v2,"v2",(double*)0);
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(%1%)",v1,"v1",
38  v2,"v2",(double*)0);
39  Eigen::Matrix<fvar<T>, R1, 1> ret(v1.rows(),1);
40  for (size_type j = 0; j < v1.rows(); ++j) {
41  Eigen::Matrix<double,R1,C1> crow = v1.row(j);
42  Eigen::Matrix<fvar<T>,R2,C2> crow2 = v2.row(j);
43  ret(j,0) = dot_product(crow, crow2);
44  }
45  return ret;
46  }
47 
48  template<typename T, int R1,int C1,int R2, int C2>
49  inline
50  Eigen::Matrix<fvar<T>, R1, 1>
51  rows_dot_product(const Eigen::Matrix<fvar<T>, R1, C1>& v1,
52  const Eigen::Matrix<double, R2, C2>& v2) {
53  stan::math::check_matching_dims("rows_dot_product(%1%)",v1,"v1",
54  v2,"v2",(double*)0);
55  Eigen::Matrix<fvar<T>, R1, 1> ret(v1.rows(),1);
56  for (size_type j = 0; j < v1.rows(); ++j) {
57  Eigen::Matrix<fvar<T>,R1,C1> crow1 = v1.row(j);
58  Eigen::Matrix<double,R2,C2> crow = v2.row(j);
59  ret(j,0) = dot_product(crow1, crow);
60  }
61  return ret;
62  }
63  }
64 }
65 #endif
bool check_matching_dims(const char *function, const Eigen::Matrix< T1, R1, C1 > &y1, const char *name1, const Eigen::Matrix< T2, R2, C2 > &y2, const char *name2, T_result *result)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Definition: typedefs.hpp:14
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–2014, Stan Development Team.