Automatic Differentiation
 
Loading...
Searching...
No Matches
multiply.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUN_MULTIPLY_HPP
2#define STAN_MATH_FWD_FUN_MULTIPLY_HPP
3
12
13namespace stan {
14namespace math {
15
16template <typename Mat1, typename Mat2,
17 require_all_eigen_vt<is_fvar, Mat1, Mat2>* = nullptr,
18 require_vt_same<Mat1, Mat2>* = nullptr,
19 require_not_eigen_row_and_col_t<Mat1, Mat2>* = nullptr>
20inline auto multiply(Mat1&& m1, Mat2&& m2) {
21 check_multiplicable("multiply", "m1", m1, "m2", m2);
22 decltype(auto) m1_ref = to_ref(m1);
23 decltype(auto) m2_ref = to_ref(m2);
24 return to_fvar(multiply(m1_ref.val(), m2_ref.val()),
25 add(multiply(m1_ref.val(), m2_ref.d()),
26 multiply(m1_ref.d(), m2_ref.val())));
27}
28
29template <typename Mat1, typename Mat2,
33inline auto multiply(Mat1&& m1, Mat2&& m2) {
34 check_multiplicable("multiply", "m1", m1, "m2", m2);
35 decltype(auto) m1_ref = to_ref(m1);
36 decltype(auto) m2_ref = to_ref(m2);
37 return to_fvar(multiply(m1_ref.val(), m2_ref), multiply(m1_ref.d(), m2_ref));
38}
39
40template <typename Mat1, typename Mat2,
41 require_eigen_vt<std::is_floating_point, Mat1>* = nullptr,
42 require_eigen_vt<is_fvar, Mat2>* = nullptr,
43 require_not_eigen_row_and_col_t<Mat1, Mat2>* = nullptr>
44inline auto multiply(Mat1&& m1, Mat2&& m2) {
45 check_multiplicable("multiply", "m1", m1, "m2", m2);
46 decltype(auto) m1_ref = to_ref(m1);
47 decltype(auto) m2_ref = to_ref(m2);
48 return to_fvar(multiply(m1_ref, m2_ref.val()), multiply(m1_ref, m2_ref.d()));
49}
50
51} // namespace math
52} // namespace stan
53#endif
require_t< container_type_check_base< is_eigen, value_type_t, TypeCheck, Check... > > require_eigen_vt
Require type satisfies is_eigen.
Definition is_eigen.hpp:155
addition_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > add(T_a &&a, T_b &&b)
auto multiply(Mat1 &&m1, Mat2 &&m2)
Return the product of the specified matrices.
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.
fvar< T > to_fvar(const T &x)
Definition to_fvar.hpp:15
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:18
require_not_t< math::conjunction< is_eigen_row_vector< Row >, is_eigen_col_vector< Col > > > require_not_eigen_row_and_col_t
Require Row is not a row vector and Col is not a column vector.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...