Stan Math Library  2.20.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 <type_traits>
8 
9 namespace stan {
10 namespace math {
11 
20 template <int R, int C, typename T>
21 inline typename std::enable_if<std::is_arithmetic<T>::value,
22  Eigen::Matrix<double, R, C> >::type
23 multiply(const Eigen::Matrix<double, R, C>& m, T c) {
24  return c * m;
25 }
26 
35 template <int R, int C, typename T>
36 inline typename std::enable_if<std::is_arithmetic<T>::value,
37  Eigen::Matrix<double, R, C> >::type
38 multiply(T c, const Eigen::Matrix<double, R, C>& m) {
39  return c * m;
40 }
41 
52 template <int R1, int C1, int R2, int C2>
53 inline Eigen::Matrix<double, R1, C2> multiply(
54  const Eigen::Matrix<double, R1, C1>& m1,
55  const Eigen::Matrix<double, R2, C2>& m2) {
56  check_multiplicable("multiply", "m1", m1, "m2", m2);
57  return m1 * m2;
58 }
59 
69 template <int C1, int R2>
70 inline double multiply(const Eigen::Matrix<double, 1, C1>& rv,
71  const Eigen::Matrix<double, R2, 1>& v) {
72  check_matching_sizes("multiply", "rv", rv, "v", v);
73  return rv.dot(v);
74 }
75 
76 } // namespace math
77 } // namespace stan
78 #endif
Eigen::Matrix< fvar< T >, R1, C1 > multiply(const Eigen::Matrix< fvar< T >, R1, C1 > &m, const fvar< T > &c)
Definition: multiply.hpp:14
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–2018, Stan Development Team.