Skip to content

Commit d648ac1

Browse files
authored
Merge pull request #2892 from stan-dev/clang16-complex
Add overloads for complex multiply to fix clang16
2 parents 9082492 + 3bced7e commit d648ac1

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

stan/math/fwd/core/operator_multiplication.hpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#define STAN_MATH_FWD_CORE_OPERATOR_MULTIPLICATION_HPP
33

44
#include <stan/math/fwd/core/fvar.hpp>
5+
#include <stan/math/fwd/core/std_complex.hpp>
6+
#include <stan/math/prim/core/operator_multiplication.hpp>
57

68
namespace stan {
79
namespace math {
@@ -45,6 +47,51 @@ inline fvar<T> operator*(const fvar<T>& x, double y) {
4547
return fvar<T>(x.val_ * y, x.d_ * y);
4648
}
4749

50+
/**
51+
* Return the product of the two complex fvar<T> arguments.
52+
*
53+
* @tparam value and tangent type for variables
54+
* @param[in] x first argument
55+
* @param[in] y second argument
56+
* @return product of arguments
57+
*/
58+
template <typename T>
59+
inline std::complex<stan::math::fvar<T>> operator*(
60+
const std::complex<stan::math::fvar<T>>& x,
61+
const std::complex<stan::math::fvar<T>>& y) {
62+
return internal::complex_multiply(x, y);
63+
}
64+
65+
/**
66+
* Return the product of std::complex<double> and
67+
* std::complex<fvar<T>> arguments.
68+
*
69+
* @tparam value and tangent type for variables
70+
* @param[in] x first argument
71+
* @param[in] y second argument
72+
* @return product of arguments
73+
*/
74+
template <typename T>
75+
inline std::complex<stan::math::fvar<T>> operator*(
76+
const std::complex<double>& x, const std::complex<stan::math::fvar<T>>& y) {
77+
return internal::complex_multiply(x, y);
78+
}
79+
80+
/**
81+
* Return the product of std::complex<double> and
82+
* std::complex<fvar<T>> arguments.
83+
*
84+
* @tparam value and tangent type for variables
85+
* @param[in] x first argument
86+
* @param[in] y second argument
87+
* @return product of arguments
88+
*/
89+
template <typename T>
90+
inline std::complex<stan::math::fvar<T>> operator*(
91+
const std::complex<stan::math::fvar<T>>& x, const std::complex<double>& y) {
92+
return internal::complex_multiply(x, y);
93+
}
94+
4895
} // namespace math
4996
} // namespace stan
5097
#endif

stan/math/rev/core/operator_multiplication.hpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33

44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/rev/core/var.hpp>
6+
#include <stan/math/rev/core/operator_addition.hpp>
7+
#include <stan/math/rev/core/operator_subtraction.hpp>
8+
#include <stan/math/rev/core/operator_plus_equal.hpp>
9+
#include <stan/math/rev/core/operator_minus_equal.hpp>
610
#include <stan/math/rev/core/vv_vari.hpp>
711
#include <stan/math/rev/core/vd_vari.hpp>
12+
#include <stan/math/prim/core/operator_multiplication.hpp>
813
#include <stan/math/prim/fun/constants.hpp>
914
#include <stan/math/prim/fun/is_any_nan.hpp>
1015
#include <stan/math/prim/fun/isinf.hpp>
@@ -112,6 +117,45 @@ inline var operator*(Arith a, const var& b) {
112117
return {new internal::multiply_vd_vari(b.vi_, a)}; // by symmetry
113118
}
114119

120+
/**
121+
* Return the product of std::complex<var> arguments.
122+
*
123+
* @param[in] x first argument
124+
* @param[in] y second argument
125+
* @return product of arguments
126+
*/
127+
inline 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+
133+
/**
134+
* Return the product of std::complex<double> and
135+
* std::complex<var> arguments.
136+
*
137+
* @param[in] x first argument
138+
* @param[in] y second argument
139+
* @return product of arguments
140+
*/
141+
inline 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+
146+
/**
147+
* Return the product of std::complex<double> and
148+
* std::complex<var> arguments.
149+
*
150+
* @param[in] x first argument
151+
* @param[in] y second argument
152+
* @return product of arguments
153+
*/
154+
inline 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+
115159
} // namespace math
116160
} // namespace stan
117161
#endif

0 commit comments

Comments
 (0)