Automatic Differentiation
 
Loading...
Searching...
No Matches
diag_post_multiply.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_DIAG_POST_MULTIPLY_HPP
2#define STAN_MATH_PRIM_FUN_DIAG_POST_MULTIPLY_HPP
3
7
8namespace stan {
9namespace math {
10
23template <typename T1, typename T2, require_eigen_t<T1>* = nullptr,
24 require_eigen_vector_t<T2>* = nullptr,
25 require_all_not_st_var<T1, T2>* = nullptr>
26inline auto diag_post_multiply(T1&& m1, T2&& m2) {
27 auto&& m1_ref = to_ref(std::forward<T1>(m1));
28 auto&& m2_ref = to_ref(std::forward<T2>(m2));
29 check_size_match("diag_post_multiply", "m2.size()", m2_ref.size(),
30 "m1.cols()", m1_ref.cols());
31 return make_holder(
32 [](auto&& m1_, auto&& m2_) {
33 return std::forward<decltype(m1_)>(m1_)
34 * std::forward<decltype(m2_)>(m2_).asDiagonal();
35 },
36 std::forward<decltype(m1_ref)>(m1_ref),
37 std::forward<decltype(m2_ref)>(m2_ref));
38}
39
40} // namespace math
41} // namespace stan
42#endif
auto diag_post_multiply(const T1 &m1, const T2 &m2)
Return the product of a matrix and the diagonal matrix formed from the vector or row_vector.
auto make_holder(F &&func, Args &&... args)
Calls given function with given arguments.
Definition holder.hpp:481
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.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.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...