Automatic Differentiation
 
Loading...
Searching...
No Matches
multiply.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_MULTIPLY_HPP
2#define STAN_MATH_PRIM_FUN_MULTIPLY_HPP
3
8#include <type_traits>
9
10namespace stan {
11namespace math {
12
23template <typename Mat, typename Scal, require_stan_scalar_t<Scal>* = nullptr,
24 require_eigen_t<Mat>* = nullptr,
25 require_all_not_st_var<Scal, Mat>* = nullptr,
26 require_all_not_complex_t<Scal, value_type_t<Mat>>* = nullptr>
27inline auto multiply(const Mat& m, Scal c) {
28 return c * m;
29}
30
43template <typename Mat, typename Scal,
46inline auto multiply(const Mat& m, Scal c) {
47 return m * c;
48}
49
62template <typename Mat, typename Scal,
65inline auto multiply(const Scal& m, const Mat& c) {
66 return m * c;
67}
68
79template <typename Scal, typename Mat, require_stan_scalar_t<Scal>* = nullptr,
80 require_eigen_t<Mat>* = nullptr,
81 require_all_not_st_var<Scal, Mat>* = nullptr,
82 require_all_not_complex_t<Scal, value_type_t<Mat>>* = nullptr>
83inline auto multiply(Scal c, const Mat& m) {
84 return c * m;
85}
86
101template <typename Mat1, typename Mat2,
104inline auto multiply(const Mat1& m1, const Mat2& m2) {
105 check_size_match("multiply", "Columns of m1", m1.cols(), "Rows of m2",
106 m2.rows());
107 return m1 * m2;
108}
109
124template <typename Mat1, typename Mat2,
128inline auto multiply(const Mat1& m1, const Mat2& m2) {
129 check_size_match("multiply", "Columns of m1", m1.cols(), "Rows of m2",
130 m2.rows());
131 return m1.lazyProduct(m2).eval();
132}
133
147template <typename RowVec, typename ColVec,
148 require_not_var_t<return_type_t<RowVec, ColVec>>* = nullptr,
149 require_eigen_row_and_col_t<RowVec, ColVec>* = nullptr>
150inline auto multiply(const RowVec& rv, const ColVec& v) {
151 check_multiplicable("multiply", "rv", rv, "v", v);
152 return dot_product(rv, v);
153}
154
164template <typename Scalar1, typename Scalar2,
166inline return_type_t<Scalar1, Scalar2> multiply(Scalar1 m, Scalar2 c) {
167 return c * m;
168}
169
170} // namespace math
171} // namespace stan
172
173#endif
require_any_t< is_complex< std::decay_t< Types > >... > require_any_complex_t
Require any of the types satisfy is_complex.
require_all_t< container_type_check_base< is_eigen, value_type_t, TypeCheck, Check >... > require_all_eigen_vt
Require all of the types satisfy is_eigen.
Definition is_eigen.hpp:133
require_all_t< is_eigen< std::decay_t< Types > >... > require_all_eigen_t
Require all of the types satisfy is_eigen.
Definition is_eigen.hpp:65
require_t< is_eigen< std::decay_t< T > > > require_eigen_t
Require type satisfies is_eigen.
Definition is_eigen.hpp:55
require_not_t< is_eigen< std::decay_t< T > > > require_not_eigen_t
Require type does not satisfy is_eigen.
Definition is_eigen.hpp:60
require_all_t< is_stan_scalar< std::decay_t< Types > >... > require_all_stan_scalar_t
Require all of the types satisfy is_stan_scalar.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
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.
auto multiply(const Mat1 &m1, const Mat2 &m2)
Return the product of the specified matrices.
Definition multiply.hpp:18
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
auto dot_product(const T_a &a, const T_b &b)
Returns the dot product of the specified vectors.
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.
std::enable_if_t< Check::value > require_t
If condition is true, template is enabled.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...