1 #ifndef STAN__AGRAD__FWD__MATRIX__MULTIPLY_HPP
2 #define STAN__AGRAD__FWD__MATRIX__MULTIPLY_HPP
5 #include <boost/math/tools/promotion.hpp>
18 template<
typename T,
int R1,
int C1>
20 Eigen::Matrix<fvar<T>,R1,C1>
22 Eigen::Matrix<fvar<T>,R1,C1> res(m.rows(),m.cols());
23 for(
int i = 0; i < m.rows(); i++) {
24 for(
int j = 0; j < m.cols(); j++)
25 res(i,j) = c * m(i,j);
30 template<
typename T,
int R2,
int C2>
32 Eigen::Matrix<fvar<T>, R2, C2>
34 Eigen::Matrix<fvar<T>,R2,C2> res(m.rows(),m.cols());
35 for(
int i = 0; i < m.rows(); i++) {
36 for(
int j = 0; j < m.cols(); j++)
37 res(i,j) = c * m(i,j);
42 template<
typename T,
int R1,
int C1>
44 Eigen::Matrix<fvar<T>,R1,C1>
46 Eigen::Matrix<fvar<T>,R1,C1> res(m.rows(),m.cols());
47 for(
int i = 0; i < m.rows(); i++) {
48 for(
int j = 0; j < m.cols(); j++)
49 res(i,j) = c * m(i,j);
54 template<
typename T,
int R1,
int C1>
56 Eigen::Matrix<fvar<T>,R1,C1>
61 template<
typename T,
int R1,
int C1>
63 Eigen::Matrix<fvar<T>,R1,C1>
68 template<
typename T,
int R1,
int C1>
70 Eigen::Matrix<fvar<T>,R1,C1>
75 template<
typename T,
int R1,
int C1,
int R2,
int C2>
77 Eigen::Matrix<fvar<T>,R1,C2>
79 const Eigen::Matrix<
fvar<T>,R2,C2>& m2) {
82 Eigen::Matrix<fvar<T>,R1,C2> result(m1.rows(),m2.cols());
83 for (
size_type i = 0; i < m1.rows(); i++) {
84 Eigen::Matrix<fvar<T>,1,C1> crow = m1.row(i);
85 for (
size_type j = 0; j < m2.cols(); j++) {
86 Eigen::Matrix<fvar<T>,R2,1> ccol = m2.col(j);
93 template<
typename T,
int R1,
int C1,
int R2,
int C2>
95 Eigen::Matrix<fvar<T>,R1,C2>
97 const Eigen::Matrix<double,R2,C2>& m2) {
100 Eigen::Matrix<fvar<T>,R1,C2> result(m1.rows(),m2.cols());
101 for (
size_type i = 0; i < m1.rows(); i++) {
102 Eigen::Matrix<fvar<T>,1,C1> crow = m1.row(i);
103 for (
size_type j = 0; j < m2.cols(); j++) {
104 Eigen::Matrix<double,R2,1> ccol = m2.col(j);
111 template<
typename T,
int R1,
int C1,
int R2,
int C2>
113 Eigen::Matrix<fvar<T>,R1,C2>
115 const Eigen::Matrix<
fvar<T>,R2,C2>& m2) {
118 Eigen::Matrix<fvar<T>,R1,C2> result(m1.rows(),m2.cols());
119 for (
size_type i = 0; i < m1.rows(); i++) {
120 Eigen::Matrix<double,1,C1> crow = m1.row(i);
121 for (
size_type j = 0; j < m2.cols(); j++) {
122 Eigen::Matrix<fvar<T>,R2,1> ccol = m2.col(j);
129 template <
typename T,
int C1,
int R2>
133 const Eigen::Matrix<
fvar<T>, R2, 1>& v) {
134 if (rv.size() != v.size())
135 throw std::domain_error(
"row vector and vector must be same length in multiply");
139 template <
typename T,
int C1,
int R2>
143 const Eigen::Matrix<double, R2, 1>& v) {
144 if (rv.size() != v.size())
145 throw std::domain_error(
"row vector and vector must be same length in multiply");
149 template <
typename T,
int C1,
int R2>
153 const Eigen::Matrix<
fvar<T>, R2, 1>& v) {
154 if (rv.size() != v.size())
155 throw std::domain_error(
"row vector and vector must be same length in multiply");
Eigen::Matrix< fvar< T >, R1, C1 > multiply(const Eigen::Matrix< fvar< T >, R1, C1 > &m, const fvar< T > &c)
bool check_multiplicable(const char *function, const T1 &y1, const char *name1, const T2 &y2, const char *name2, T_result *result)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
fvar< T > dot_product(const Eigen::Matrix< fvar< T >, R1, C1 > &v1, const Eigen::Matrix< fvar< T >, R2, C2 > &v2)