1 #ifndef STAN_MATH_FWD_MAT_FUN_MULTIPLY_HPP 2 #define STAN_MATH_FWD_MAT_FUN_MULTIPLY_HPP 13 template <
typename T,
int R1,
int C1>
14 inline Eigen::Matrix<fvar<T>, R1, C1>
multiply(
16 Eigen::Matrix<fvar<T>, R1, C1> res(m.rows(), m.cols());
17 for (
int i = 0; i < m.rows(); i++) {
18 for (
int j = 0; j < m.cols(); j++)
19 res(i, j) = c * m(i, j);
24 template <
typename T,
int R2,
int C2>
25 inline Eigen::Matrix<fvar<T>, R2, C2>
multiply(
26 const Eigen::Matrix<
fvar<T>, R2, C2>& m,
double c) {
27 Eigen::Matrix<fvar<T>, R2, C2> res(m.rows(), m.cols());
28 for (
int i = 0; i < m.rows(); i++) {
29 for (
int j = 0; j < m.cols(); j++)
30 res(i, j) = c * m(i, j);
35 template <
typename T,
int R1,
int C1>
36 inline Eigen::Matrix<fvar<T>, R1, C1>
multiply(
37 const Eigen::Matrix<double, R1, C1>& m,
const fvar<T>& c) {
38 Eigen::Matrix<fvar<T>, R1, C1> res(m.rows(), m.cols());
39 for (
int i = 0; i < m.rows(); i++) {
40 for (
int j = 0; j < m.cols(); j++)
41 res(i, j) = c * m(i, j);
46 template <
typename T,
int R1,
int C1>
47 inline Eigen::Matrix<fvar<T>, R1, C1>
multiply(
52 template <
typename T,
int R1,
int C1>
53 inline Eigen::Matrix<fvar<T>, R1, C1>
multiply(
54 double c,
const Eigen::Matrix<
fvar<T>, R1, C1>& m) {
58 template <
typename T,
int R1,
int C1>
59 inline Eigen::Matrix<fvar<T>, R1, C1>
multiply(
60 const fvar<T>& c,
const Eigen::Matrix<double, R1, C1>& m) {
64 template <
typename T,
int R1,
int C1,
int R2,
int C2>
65 inline Eigen::Matrix<fvar<T>, R1, C2>
multiply(
66 const Eigen::Matrix<
fvar<T>, R1, C1>& m1,
67 const Eigen::Matrix<
fvar<T>, R2, C2>& m2) {
69 Eigen::Matrix<fvar<T>, R1, C2> result(m1.rows(), m2.cols());
70 for (
size_type i = 0; i < m1.rows(); i++) {
71 Eigen::Matrix<fvar<T>, 1, C1> crow = m1.row(i);
72 for (
size_type j = 0; j < m2.cols(); j++) {
73 Eigen::Matrix<fvar<T>, R2, 1> ccol = m2.col(j);
80 template <
typename T,
int R1,
int C1,
int R2,
int C2>
81 inline Eigen::Matrix<fvar<T>, R1, C2>
multiply(
82 const Eigen::Matrix<
fvar<T>, R1, C1>& m1,
83 const Eigen::Matrix<double, R2, C2>& m2) {
85 Eigen::Matrix<fvar<T>, R1, C2> result(m1.rows(), m2.cols());
86 for (
size_type i = 0; i < m1.rows(); i++) {
87 Eigen::Matrix<fvar<T>, 1, C1> crow = m1.row(i);
88 for (
size_type j = 0; j < m2.cols(); j++) {
89 Eigen::Matrix<double, R2, 1> ccol = m2.col(j);
96 template <
typename T,
int R1,
int C1,
int R2,
int C2>
97 inline Eigen::Matrix<fvar<T>, R1, C2>
multiply(
98 const Eigen::Matrix<double, R1, C1>& m1,
99 const Eigen::Matrix<
fvar<T>, R2, C2>& m2) {
101 Eigen::Matrix<fvar<T>, R1, C2> result(m1.rows(), m2.cols());
102 for (
size_type i = 0; i < m1.rows(); i++) {
103 Eigen::Matrix<double, 1, C1> crow = m1.row(i);
104 for (
size_type j = 0; j < m2.cols(); j++) {
105 Eigen::Matrix<fvar<T>, R2, 1> ccol = m2.col(j);
112 template <
typename T,
int C1,
int R2>
114 const Eigen::Matrix<
fvar<T>, R2, 1>& v) {
119 template <
typename T,
int C1,
int R2>
121 const Eigen::Matrix<double, R2, 1>& v) {
126 template <
typename T,
int C1,
int R2>
128 const Eigen::Matrix<
fvar<T>, R2, 1>& v) {
Eigen::Matrix< fvar< T >, R1, C1 > multiply(const Eigen::Matrix< fvar< T >, R1, C1 > &m, const fvar< T > &c)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Type for sizes and indexes in an Eigen matrix with double e.
fvar< T > dot_product(const Eigen::Matrix< fvar< T >, R1, C1 > &v1, const Eigen::Matrix< fvar< T >, R2, C2 > &v2)
void check_multiplicable(const char *function, const char *name1, const T1 &y1, const char *name2, const T2 &y2)
Check if the matrices can be multiplied.
This template class represents scalars used in forward-mode automatic differentiation, which consist of values and directional derivatives of the specified template type.