Automatic Differentiation
 
Loading...
Searching...
No Matches
elt_divide.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_ELT_DIVIDE_HPP
2#define STAN_MATH_PRIM_FUN_ELT_DIVIDE_HPP
3
8
9namespace stan {
10namespace math {
11
22template <typename Mat1, typename Mat2,
23 require_all_eigen_t<Mat1, Mat2>* = nullptr,
24 require_all_not_st_var<Mat1, Mat2>* = nullptr>
25inline auto elt_divide(Mat1&& m1, Mat2&& m2) {
26 check_matching_dims("elt_divide", "m1", m1, "m2", m2);
27 return make_holder(
28 [&](auto&& m1_, auto&& m2_) {
29 return (m1_.array() / m2_.array()).matrix();
30 },
31 std::forward<Mat1>(m1), std::forward<Mat2>(m2));
32}
33
45template <typename Mat, typename Scal, require_matrix_t<Mat>* = nullptr,
46 require_stan_scalar_t<Scal>* = nullptr>
47inline auto elt_divide(Mat&& m, Scal s) {
48 return divide(std::forward<Mat>(m), s);
49}
50
62template <typename Scal, typename Mat, require_stan_scalar_t<Scal>* = nullptr,
63 require_eigen_t<Mat>* = nullptr>
64inline auto elt_divide(Scal s, Mat&& m) {
65 return make_holder([s](auto&& m_) { return (s / m_.array()).matrix(); },
66 std::forward<Mat>(m));
67}
68
69template <typename Scal1, typename Scal2,
71inline auto elt_divide(Scal1 s1, Scal2 s2) {
72 return s1 / s2;
73}
74
75} // namespace math
76} // namespace stan
77
78#endif
elt_divide_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > elt_divide(T_a &&a, T_b &&b)
auto divide(T_a &&a, double d)
Returns the elementwise division of the kernel generator expression.
Definition divide.hpp:20
require_all_t< is_stan_scalar< std::decay_t< Types > >... > require_all_stan_scalar_t
Require all of the types satisfy is_stan_scalar.
void check_matching_dims(const char *function, const char *name1, const T1 &y1, const char *name2, const T2 &y2)
Check if the two containers have the same dimensions.
auto make_holder(F &&func, Args &&... args)
Calls given function with given arguments.
Definition holder.hpp:481
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...