Stan Math Library  2.15.0
reverse mode automatic differentiation
multiply.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_MULTIPLY_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_MULTIPLY_HPP
3 
7 #include <boost/type_traits/is_arithmetic.hpp>
8 #include <boost/utility/enable_if.hpp>
9 
10 namespace stan {
11  namespace math {
12 
21  template <int R, int C, typename T>
22  inline
23  typename boost::enable_if_c<boost::is_arithmetic<T>::value,
24  Eigen::Matrix<double, R, C> >::type
25  multiply(const Eigen::Matrix<double, R, C>& m,
26  T c) {
27  return c * m;
28  }
29 
38  template <int R, int C, typename T>
39  inline
40  typename boost::enable_if_c<boost::is_arithmetic<T>::value,
41  Eigen::Matrix<double, R, C> >::type
42  multiply(T c,
43  const Eigen::Matrix<double, R, C>& m) {
44  return c * m;
45  }
46 
57  template<int R1, int C1, int R2, int C2>
58  inline Eigen::Matrix<double, R1, C2>
59  multiply(const Eigen::Matrix<double, R1, C1>& m1,
60  const Eigen::Matrix<double, R2, C2>& m2) {
61  check_multiplicable("multiply",
62  "m1", m1,
63  "m2", m2);
64  return m1*m2;
65  }
66 
76  template<int C1, int R2>
77  inline double multiply(const Eigen::Matrix<double, 1, C1>& rv,
78  const Eigen::Matrix<double, R2, 1>& v) {
79  check_matching_sizes("multiply",
80  "rv", rv,
81  "v", v);
82  return rv.dot(v);
83  }
84 
85  }
86 }
87 #endif
Eigen::Matrix< fvar< T >, R1, C1 > multiply(const Eigen::Matrix< fvar< T >, R1, C1 > &m, const fvar< T > &c)
Definition: multiply.hpp:20
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.
void check_matching_sizes(const char *function, const char *name1, const T_y1 &y1, const char *name2, const T_y2 &y2)
Check if two structures at the same size.

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