Stan Math Library  2.20.0
reverse mode automatic differentiation
rows_dot_product.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_MAT_FUN_ROWS_DOT_PRODUCT_HPP
2 #define STAN_MATH_FWD_MAT_FUN_ROWS_DOT_PRODUCT_HPP
3 
7 #include <stan/math/fwd/core.hpp>
8 
9 namespace stan {
10 namespace math {
11 
12 template <typename T, int R1, int C1, int R2, int C2>
13 inline Eigen::Matrix<fvar<T>, R1, 1> rows_dot_product(
14  const Eigen::Matrix<fvar<T>, R1, C1>& v1,
15  const Eigen::Matrix<fvar<T>, R2, C2>& v2) {
16  check_matching_dims("rows_dot_product", "v1", v1, "v2", v2);
17  Eigen::Matrix<fvar<T>, R1, 1> ret(v1.rows(), 1);
18  for (size_type j = 0; j < v1.rows(); ++j) {
19  Eigen::Matrix<fvar<T>, R1, C1> crow1 = v1.row(j);
20  Eigen::Matrix<fvar<T>, R2, C2> crow2 = v2.row(j);
21  ret(j, 0) = dot_product(crow1, crow2);
22  }
23  return ret;
24 }
25 
26 template <typename T, int R1, int C1, int R2, int C2>
27 inline Eigen::Matrix<fvar<T>, R1, 1> rows_dot_product(
28  const Eigen::Matrix<double, R1, C1>& v1,
29  const Eigen::Matrix<fvar<T>, R2, C2>& v2) {
30  check_matching_dims("rows_dot_product", "v1", v1, "v2", v2);
31  Eigen::Matrix<fvar<T>, R1, 1> ret(v1.rows(), 1);
32  for (size_type j = 0; j < v1.rows(); ++j) {
33  Eigen::Matrix<double, R1, C1> crow = v1.row(j);
34  Eigen::Matrix<fvar<T>, R2, C2> crow2 = v2.row(j);
35  ret(j, 0) = dot_product(crow, crow2);
36  }
37  return ret;
38 }
39 
40 template <typename T, int R1, int C1, int R2, int C2>
41 inline Eigen::Matrix<fvar<T>, R1, 1> rows_dot_product(
42  const Eigen::Matrix<fvar<T>, R1, C1>& v1,
43  const Eigen::Matrix<double, R2, C2>& v2) {
44  check_matching_dims("rows_dot_product", "v1", v1, "v2", v2);
45  Eigen::Matrix<fvar<T>, R1, 1> ret(v1.rows(), 1);
46  for (size_type j = 0; j < v1.rows(); ++j) {
47  Eigen::Matrix<fvar<T>, R1, C1> crow1 = v1.row(j);
48  Eigen::Matrix<double, R2, C2> crow = v2.row(j);
49  ret(j, 0) = dot_product(crow1, crow);
50  }
51  return ret;
52 }
53 
54 } // namespace math
55 } // namespace stan
56 #endif
void check_matching_dims(const char *function, const char *name1, const matrix_cl &y1, const char *name2, const matrix_cl &y2)
Check if two matrix_cls have the same dimensions.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Type for sizes and indexes in an Eigen matrix with double e.
Definition: typedefs.hpp:11
fvar< T > dot_product(const Eigen::Matrix< fvar< T >, R1, C1 > &v1, const Eigen::Matrix< fvar< T >, R2, C2 > &v2)
Definition: dot_product.hpp:14
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)
This template class represents scalars used in forward-mode automatic differentiation, which consist of values and directional derivatives of the specified template type.
Definition: fvar.hpp:41

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