Stan Math Library: stan/math/prim/mat/fun/multiply.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/prim/mat/err/check_matching_sizes.hpp>
6 #include <stan/math/prim/mat/err/check_multiplicable.hpp>
7 #include <boost/type_traits/is_arithmetic.hpp>
8 #include <boost/utility/enable_if.hpp>
9 #include <stdexcept>
10
11 namespace stan {
12 namespace math {
13
22 template <int R, int C, typename T>
23 inline
24 typename boost::enable_if_c<boost::is_arithmetic<T>::value,
25 Eigen::Matrix<double, R, C> >::type
26 multiply(const Eigen::Matrix<double, R, C>& m,
27 T c) {
28 return c * m;
29 }
30
31 // FIXME: apply above pattern everywhere below to remove
32 // extra defs, etc.
33
42 template <int R, int C, typename T>
43 inline
44 typename boost::enable_if_c<boost::is_arithmetic<T>::value,
45 Eigen::Matrix<double, R, C> >::type
46 multiply(T c,
47 const Eigen::Matrix<double, R, C>& m) {
48 return c * m;
49 }
50
61 template<int R1, int C1, int R2, int C2>
62 inline Eigen::Matrix<double, R1, C2>
63 multiply(const Eigen::Matrix<double, R1, C1>& m1,
64 const Eigen::Matrix<double, R2, C2>& m2) {
65 stan::math::check_multiplicable("multiply",
66 "m1", m1,
67 "m2", m2);
68 return m1*m2;
69 }
70
80 template<int C1, int R2>
81 inline double multiply(const Eigen::Matrix<double, 1, C1>& rv,
82 const Eigen::Matrix<double, R2, 1>& v) {
83 stan::math::check_matching_sizes("multiply",
84 "rv", rv,
85 "v", v);
86 if (rv.size() != v.size())
87 throw std::domain_error("rv.size() != v.size()");
88 return rv.dot(v);
89 }
90
91 }
92 }
93 #endif
check_multiplicable.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::multiply
Eigen::Matrix< fvar< T >, R1, C1 > multiply(const Eigen::Matrix< fvar< T >, R1, C1 > &m, const fvar< T > &c)
Definition: multiply.hpp:21
check_matching_sizes.hpp
stan::math::check_multiplicable
bool check_multiplicable(const char *function, const char *name1, const T1 &y1, const char *name2, const T2 &y2)
Return true if the matrices can be multiplied.
Definition: check_multiplicable.hpp:33
stan::math::check_matching_sizes
bool check_matching_sizes(const char *function, const char *name1, const T_y1 &y1, const char *name2, const T_y2 &y2)
Return true if two structures at the same size.
Definition: check_matching_sizes.hpp:29
stan::math::domain_error
void domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
Definition: domain_error.hpp:32
Eigen.hpp

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