Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
columns_dot_product.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__FWD__MATRIX__COLUMNS__DOT_PRODUCT_HPP
2 #define STAN__AGRAD__FWD__MATRIX__COLUMNS__DOT_PRODUCT_HPP
3 
4 #include <vector>
10 #include <stan/agrad/fwd/fvar.hpp>
11 
12 namespace stan {
13  namespace agrad {
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(%1%)",v1,"v1",
21  v2,"v2",(double*)0);
22  Eigen::Matrix<fvar<T>, 1, C1> ret(1,v1.cols());
23  for (size_type j = 0; j < v1.cols(); ++j) {
24  Eigen::Matrix<fvar<T>,R1,C1> ccol1 = v1.col(j);
25  Eigen::Matrix<fvar<T>,R2,C2> ccol2 = v2.col(j);
26  ret(0,j) = dot_product(ccol1, ccol2);
27  }
28  return ret;
29  }
30 
31  template<typename T, int R1,int C1,int R2, int C2>
32  inline
33  Eigen::Matrix<fvar<T>, 1, C1>
34  columns_dot_product(const Eigen::Matrix<fvar<T>, R1, C1>& v1,
35  const Eigen::Matrix<double, R2, C2>& v2) {
36  stan::math::check_matching_dims("columns_dot_product(%1%)",v1,"v1",
37  v2,"v2",(double*)0);
38  Eigen::Matrix<fvar<T>, 1, C1> ret(1,v1.cols());
39  for (size_type j = 0; j < v1.cols(); ++j) {
40  Eigen::Matrix<fvar<T>,R1,C1> ccol1 = v1.col(j);
41  Eigen::Matrix<double,R2,C2> ccol = v2.col(j);
42  ret(0,j) = dot_product(ccol1, ccol);
43  }
44  return ret;
45  }
46 
47  template<typename T, int R1,int C1,int R2, int C2>
48  inline
49  Eigen::Matrix<fvar<T>, 1, C1>
50  columns_dot_product(const Eigen::Matrix<double, R1, C1>& v1,
51  const Eigen::Matrix<fvar<T>, R2, C2>& v2) {
52  stan::math::check_matching_dims("columns_dot_product(%1%)",v1,"v1",
53  v2,"v2",(double*)0);
54  Eigen::Matrix<fvar<T>, 1, C1> ret(1,v1.cols());
55  for (size_type j = 0; j < v1.cols(); ++j) {
56  Eigen::Matrix<double,R1,C1> ccol = v1.col(j);
57  Eigen::Matrix<fvar<T>,R2,C2> ccol2 = v2.col(j);
58  ret(0,j) = dot_product(ccol, ccol2);
59  }
60  return ret;
61  }
62  }
63 }
64 #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 >, 1, C1 > columns_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.