Skip to content

Commit f7161f5

Browse files
committed
Add additional overloads
1 parent b7102d7 commit f7161f5

6 files changed

Lines changed: 218 additions & 0 deletions

File tree

stan/math/fwd/core/operator_addition.hpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#define STAN_MATH_FWD_CORE_OPERATOR_ADDITION_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_addition.hpp>
57

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

50+
/**
51+
* Return the sum 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 sum of arguments
57+
*/
58+
template <typename T>
59+
inline std::complex<stan::math::fvar<T>>
60+
operator+(const std::complex<stan::math::fvar<T>>& x,
61+
const std::complex<stan::math::fvar<T>>& y) {
62+
return internal::complex_add(x, y);
63+
}
64+
65+
/**
66+
* Return the sum 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 sum of arguments
73+
*/
74+
template <typename T>
75+
inline std::complex<stan::math::fvar<T>>
76+
operator+(const std::complex<double>& x,
77+
const std::complex<stan::math::fvar<T>>& y) {
78+
return internal::complex_add(x, y);
79+
}
80+
81+
/**
82+
* Return the sum of std::complex<double> and
83+
* std::complex<fvar<T>> arguments.
84+
*
85+
* @tparam value and tangent type for variables
86+
* @param[in] x first argument
87+
* @param[in] y second argument
88+
* @return sum of arguments
89+
*/
90+
template <typename T>
91+
inline std::complex<stan::math::fvar<T>>
92+
operator+(const std::complex<stan::math::fvar<T>>& x,
93+
const std::complex<double>& y) {
94+
return internal::complex_add(x, y);
95+
}
96+
4897
} // namespace math
4998
} // namespace stan
5099
#endif

stan/math/fwd/core/operator_multiplication.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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>
56
#include <stan/math/prim/core/operator_multiplication.hpp>
67

78
namespace stan {

stan/math/fwd/core/operator_subtraction.hpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#define STAN_MATH_FWD_CORE_OPERATOR_SUBTRACTION_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_subtraction.hpp>
57

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

50+
/**
51+
* Return the difference 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 subtraction of arguments
57+
*/
58+
template <typename T>
59+
inline std::complex<stan::math::fvar<T>>
60+
operator-(const std::complex<stan::math::fvar<T>>& x,
61+
const std::complex<stan::math::fvar<T>>& y) {
62+
return internal::complex_subtract(x, y);
63+
}
64+
65+
/**
66+
* Return the difference 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 subtraction of arguments
73+
*/
74+
template <typename T>
75+
inline std::complex<stan::math::fvar<T>>
76+
operator-(const std::complex<double>& x,
77+
const std::complex<stan::math::fvar<T>>& y) {
78+
return internal::complex_subtract(x, y);
79+
}
80+
81+
/**
82+
* Return the difference of std::complex<double> and
83+
* std::complex<fvar<T>> arguments.
84+
*
85+
* @tparam value and tangent type for variables
86+
* @param[in] x first argument
87+
* @param[in] y second argument
88+
* @return subtraction of arguments
89+
*/
90+
template <typename T>
91+
inline std::complex<stan::math::fvar<T>>
92+
operator-(const std::complex<stan::math::fvar<T>>& x,
93+
const std::complex<double>& y) {
94+
return internal::complex_subtract(x, y);
95+
}
96+
4897
} // namespace math
4998
} // namespace stan
5099
#endif

stan/math/rev/core/operator_addition.hpp

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

44
#include <stan/math/rev/meta.hpp>
55
#include <stan/math/rev/core/var.hpp>
6+
#include <stan/math/rev/core/std_complex.hpp>
67
#include <stan/math/prim/err/check_matching_dims.hpp>
78
#include <stan/math/rev/core/callback_vari.hpp>
89
#include <stan/math/prim/fun/as_column_vector_or_scalar.hpp>
910
#include <stan/math/prim/fun/as_array_or_scalar.hpp>
1011
#include <stan/math/prim/fun/constants.hpp>
12+
#include <stan/math/prim/core/operator_addition.hpp>
1113

1214
namespace stan {
1315
namespace math {
@@ -278,6 +280,47 @@ inline auto operator+(const VarMat1& a, const VarMat2& b) {
278280
return add(a, b);
279281
}
280282

283+
/**
284+
* Return the sum of std::complex<var> arguments.
285+
*
286+
* @param[in] x first argument
287+
* @param[in] y second argument
288+
* @return sum of arguments
289+
*/
290+
inline std::complex<stan::math::var>
291+
operator+(const std::complex<stan::math::var>& x,
292+
const std::complex<stan::math::var>& y) {
293+
return internal::complex_add(x, y);
294+
}
295+
296+
/**
297+
* Return the sum of std::complex<double> and
298+
* std::complex<var> arguments.
299+
*
300+
* @param[in] x first argument
301+
* @param[in] y second argument
302+
* @return sum of arguments
303+
*/
304+
inline std::complex<stan::math::var>
305+
operator+(const std::complex<double>& x,
306+
const std::complex<stan::math::var>& y) {
307+
return internal::complex_add(x, y);
308+
}
309+
310+
/**
311+
* Return the sum of std::complex<double> and
312+
* std::complex<var> arguments.
313+
*
314+
* @param[in] x first argument
315+
* @param[in] y second argument
316+
* @return sum of arguments
317+
*/
318+
inline std::complex<stan::math::var>
319+
operator+(const std::complex<stan::math::var>& x,
320+
const std::complex<double>& y) {
321+
return internal::complex_add(x, y);
322+
}
323+
281324
} // namespace math
282325
} // namespace stan
283326
#endif

stan/math/rev/core/operator_division.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,44 @@ inline auto operator/(const T1& dividend, const T2& divisor) {
256256
return divide(dividend, divisor);
257257
}
258258

259+
/**
260+
* Return the division of std::complex<var> arguments.
261+
*
262+
* @param[in] x first argument
263+
* @param[in] y second argument
264+
* @return division of arguments
265+
*/
259266
inline std::complex<var> operator/(const std::complex<var>& x1,
260267
const std::complex<var>& x2) {
261268
return internal::complex_divide(x1, x2);
262269
}
263270

271+
/**
272+
* Return the division of std::complex<double> and
273+
* std::complex<var> arguments.
274+
*
275+
* @param[in] x first argument
276+
* @param[in] y second argument
277+
* @return division of arguments
278+
*/
279+
inline std::complex<var> operator/(const std::complex<double>& x1,
280+
const std::complex<var>& x2) {
281+
return internal::complex_divide(x1, x2);
282+
}
283+
284+
/**
285+
* Return the division of std::complex<double> and
286+
* std::complex<var> arguments.
287+
*
288+
* @param[in] x first argument
289+
* @param[in] y second argument
290+
* @return division of arguments
291+
*/
292+
inline std::complex<var> operator/(const std::complex<var>& x1,
293+
const std::complex<double>& x2) {
294+
return internal::complex_divide(x1, x2);
295+
}
296+
264297
} // namespace math
265298
} // namespace stan
266299
#endif

stan/math/rev/core/operator_subtraction.hpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
#include <stan/math/rev/meta.hpp>
55
#include <stan/math/rev/core/var.hpp>
6+
#include <stan/math/rev/core/std_complex.hpp>
67
#include <stan/math/rev/core/arena_matrix.hpp>
78
#include <stan/math/rev/core/callback_vari.hpp>
89
#include <stan/math/prim/fun/as_column_vector_or_scalar.hpp>
910
#include <stan/math/prim/fun/as_array_or_scalar.hpp>
1011
#include <stan/math/prim/fun/constants.hpp>
1112
#include <stan/math/prim/fun/is_any_nan.hpp>
13+
#include <stan/math/prim/core/operator_subtraction.hpp>
1214

1315
namespace stan {
1416
namespace math {
@@ -310,6 +312,47 @@ inline auto operator-(const VarMat1& a, const VarMat2& b) {
310312
return subtract(a, b);
311313
}
312314

315+
/**
316+
* Return the difference of std::complex<var> arguments.
317+
*
318+
* @param[in] x first argument
319+
* @param[in] y second argument
320+
* @return subtraction of arguments
321+
*/
322+
inline std::complex<stan::math::var>
323+
operator-(const std::complex<stan::math::var>& x,
324+
const std::complex<stan::math::var>& y) {
325+
return internal::complex_subtract(x, y);
326+
}
327+
328+
/**
329+
* Return the difference of std::complex<double> and
330+
* std::complex<var> arguments.
331+
*
332+
* @param[in] x first argument
333+
* @param[in] y second argument
334+
* @return subtraction of arguments
335+
*/
336+
inline std::complex<stan::math::var>
337+
operator-(const std::complex<double>& x,
338+
const std::complex<stan::math::var>& y) {
339+
return internal::complex_subtract(x, y);
340+
}
341+
342+
/**
343+
* Return the difference of std::complex<double> and
344+
* std::complex<var> arguments.
345+
*
346+
* @param[in] x first argument
347+
* @param[in] y second argument
348+
* @return subtraction of arguments
349+
*/
350+
inline std::complex<stan::math::var>
351+
operator-(const std::complex<stan::math::var>& x,
352+
const std::complex<double>& y) {
353+
return internal::complex_subtract(x, y);
354+
}
355+
313356
} // namespace math
314357
} // namespace stan
315358
#endif

0 commit comments

Comments
 (0)