Automatic Differentiation
 
Loading...
Searching...
No Matches
operator_multiplication.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_CORE_OPERATOR_MULTIPLICATION_HPP
2#define STAN_MATH_REV_CORE_OPERATOR_MULTIPLICATION_HPP
3
17
18namespace stan {
19namespace math {
20
21namespace internal {
22class multiply_vv_vari final : public op_vv_vari {
23 public:
25 : op_vv_vari(avi->val_ * bvi->val_, avi, bvi) {}
26 void chain() {
27 avi_->adj_ += bvi_->val_ * adj_;
28 bvi_->adj_ += avi_->val_ * adj_;
29 }
30};
31
32class multiply_vd_vari final : public op_vd_vari {
33 public:
34 multiply_vd_vari(vari* avi, double b) : op_vd_vari(avi->val_ * b, avi, b) {}
35 void chain() { avi_->adj_ += adj_ * bd_; }
36};
37} // namespace internal
38
76inline var operator*(const var& a, const var& b) {
77 return {new internal::multiply_vv_vari(a.vi_, b.vi_)};
78}
79
92template <typename Arith, require_arithmetic_t<Arith>* = nullptr>
93inline var operator*(const var& a, Arith b) {
94 if (b == 1.0) {
95 return a;
96 }
97 return {new internal::multiply_vd_vari(a.vi_, b)};
98}
99
112template <typename Arith, require_arithmetic_t<Arith>* = nullptr>
113inline var operator*(Arith a, const var& b) {
114 if (a == 1.0) {
115 return b;
116 }
117 return {new internal::multiply_vd_vari(b.vi_, a)}; // by symmetry
118}
119
127inline std::complex<stan::math::var> operator*(
128 const std::complex<stan::math::var>& x,
129 const std::complex<stan::math::var>& y) {
130 return internal::complex_multiply(x, y);
131}
132
141inline std::complex<stan::math::var> operator*(
142 const std::complex<double>& x, const std::complex<stan::math::var>& y) {
143 return internal::complex_multiply(x, y);
144}
145
154inline std::complex<stan::math::var> operator*(
155 const std::complex<stan::math::var>& x, const std::complex<double>& y) {
156 return internal::complex_multiply(x, y);
157}
158
159} // namespace math
160} // namespace stan
161#endif
complex_return_t< U, V > complex_multiply(const U &lhs, const V &rhs)
Return the product of the specified arguments.
fvar< T > operator*(const fvar< T > &x, const fvar< T > &y)
Return the product of the two arguments.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9