| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/prim/mat/fun/typedefs.hpp>
6 #include <stan/math/prim/mat/err/check_matching_dims.hpp>
7 #include <stan/math/fwd/mat/fun/typedefs.hpp>
8 #include <stan/math/fwd/mat/fun/dot_product.hpp>
9 #include <stan/math/fwd/core.hpp>
10 #include <vector>
11
12 namespace stan {
13 namespace math {
14
15 template<typename T, int R1, int C1, int R2, int C2>
16 inline
17 Eigen::Matrix<fvar<T>, R1, 1>
18 rows_dot_product(const Eigen::Matrix<fvar<T>, R1, C1>& v1,
19 const Eigen::Matrix<fvar<T>, R2, C2>& v2) {
20 check_matching_dims("rows_dot_product", "v1", v1, "v2", v2);
21 Eigen::Matrix<fvar<T>, R1, 1> ret(v1.rows(), 1);
22 for (size_type j = 0; j < v1.rows(); ++j) {
23 Eigen::Matrix<fvar<T>, R1, C1> crow1 = v1.row(j);
24 Eigen::Matrix<fvar<T>, R2, C2> crow2 = v2.row(j);
25 ret(j, 0) = dot_product(crow1, crow2);
26 }
27 return ret;
28 }
29
30 template<typename T, int R1, int C1, int R2, int C2>
31 inline
32 Eigen::Matrix<fvar<T>, R1, 1>
33 rows_dot_product(const Eigen::Matrix<double, R1, C1>& v1,
34 const Eigen::Matrix<fvar<T>, R2, C2>& v2) {
35 check_matching_dims("rows_dot_product", "v1", v1, "v2", v2);
36 Eigen::Matrix<fvar<T>, R1, 1> ret(v1.rows(), 1);
37 for (size_type j = 0; j < v1.rows(); ++j) {
38 Eigen::Matrix<double, R1, C1> crow = v1.row(j);
39 Eigen::Matrix<fvar<T>, R2, C2> crow2 = v2.row(j);
40 ret(j, 0) = dot_product(crow, crow2);
41 }
42 return ret;
43 }
44
45 template<typename T, int R1, int C1, int R2, int C2>
46 inline
47 Eigen::Matrix<fvar<T>, R1, 1>
48 rows_dot_product(const Eigen::Matrix<fvar<T>, R1, C1>& v1,
49 const Eigen::Matrix<double, R2, C2>& v2) {
50 check_matching_dims("rows_dot_product", "v1", v1, "v2", v2);
51 Eigen::Matrix<fvar<T>, R1, 1> ret(v1.rows(), 1);
52 for (size_type j = 0; j < v1.rows(); ++j) {
53 Eigen::Matrix<fvar<T>, R1, C1> crow1 = v1.row(j);
54 Eigen::Matrix<double, R2, C2> crow = v2.row(j);
55 ret(j, 0) = dot_product(crow1, crow);
56 }
57 return ret;
58 }
59
60 }
61 }
62 #endif
typedefs.hpp
check_matching_dims.hpp
core.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::size_type
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:13
stan::math::check_matching_dims
bool check_matching_dims(const char *function, const char *name1, const Eigen::Matrix< T1, R1, C1 > &y1, const char *name2, const Eigen::Matrix< T2, R2, C2 > &y2)
Return true if the two matrices are of the same size.
Definition: check_matching_dims.hpp:37
dot_product.hpp
stan::math::dot_product
fvar< T > dot_product(const Eigen::Matrix< fvar< T >, R1, C1 > &v1, const Eigen::Matrix< fvar< T >, R2, C2 > &v2)
Definition: dot_product.hpp:18
Eigen.hpp
stan::math::rows_dot_product
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)
Definition: rows_dot_product.hpp:18
stan::math::fvar
Definition: fvar.hpp:12
typedefs.hpp

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