| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
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 <boost/type_traits/is_arithmetic.hpp>
5 #include <boost/utility/enable_if.hpp>
6 #include <stan/math/prim/mat/fun/Eigen.hpp>
7 #include <stan/math/prim/mat/err/check_matching_sizes.hpp>
8 #include <stan/math/prim/mat/err/check_multiplicable.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
30 // FIXME: apply above pattern everywhere below to remove
31 // extra defs, etc.
32
41 template <int R, int C, typename T>
42 inline
43 typename boost::enable_if_c<boost::is_arithmetic<T>::value,
44 Eigen::Matrix<double, R, C> >::type
45 multiply(T c,
46 const Eigen::Matrix<double, R, C>& m) {
47 return c * m;
48 }
49
60 template<int R1, int C1, int R2, int C2>
61 inline Eigen::Matrix<double, R1, C2>
62 multiply(const Eigen::Matrix<double, R1, C1>& m1,
63 const Eigen::Matrix<double, R2, C2>& m2) {
64 stan::math::check_multiplicable("multiply",
65 "m1", m1,
66 "m2", m2);
67 return m1*m2;
68 }
69
79 template<int C1, int R2>
80 inline double multiply(const Eigen::Matrix<double, 1, C1>& rv,
81 const Eigen::Matrix<double, R2, 1>& v) {
82 stan::math::check_matching_sizes("multiply",
83 "rv", rv,
84 "v", v);
85 if (rv.size() != v.size())
86 throw std::domain_error("rv.size() != v.size()");
87 return rv.dot(v);
88 }
89
90 }
91 }
92 #endif
check_multiplicable.hpp
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:20
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–2015, Stan Development Team.