Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overloads for complex multiply to fix clang16 #2892

Merged
merged 8 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions stan/math/fwd/core/operator_multiplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define STAN_MATH_FWD_CORE_OPERATOR_MULTIPLICATION_HPP

#include <stan/math/fwd/core/fvar.hpp>
#include <stan/math/fwd/core/std_complex.hpp>
#include <stan/math/prim/core/operator_multiplication.hpp>

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

/**
* Return the product of the two complex fvar<T> arguments.
*
* @tparam value and tangent type for variables
* @param[in] x first argument
* @param[in] y second argument
* @return product of arguments
*/
template <typename T>
inline std::complex<stan::math::fvar<T>> operator*(
const std::complex<stan::math::fvar<T>>& x,
const std::complex<stan::math::fvar<T>>& y) {
return internal::complex_multiply(x, y);
}

/**
* Return the product of std::complex<double> and
* std::complex<fvar<T>> arguments.
*
* @tparam value and tangent type for variables
* @param[in] x first argument
* @param[in] y second argument
* @return product of arguments
*/
template <typename T>
inline std::complex<stan::math::fvar<T>> operator*(
const std::complex<double>& x, const std::complex<stan::math::fvar<T>>& y) {
return internal::complex_multiply(x, y);
}

/**
* Return the product of std::complex<double> and
* std::complex<fvar<T>> arguments.
*
* @tparam value and tangent type for variables
* @param[in] x first argument
* @param[in] y second argument
* @return product of arguments
*/
template <typename T>
inline std::complex<stan::math::fvar<T>> operator*(
const std::complex<stan::math::fvar<T>>& x, const std::complex<double>& y) {
return internal::complex_multiply(x, y);
}

} // namespace math
} // namespace stan
#endif
44 changes: 44 additions & 0 deletions stan/math/rev/core/operator_multiplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@

#include <stan/math/prim/meta.hpp>
#include <stan/math/rev/core/var.hpp>
#include <stan/math/rev/core/operator_addition.hpp>
#include <stan/math/rev/core/operator_subtraction.hpp>
#include <stan/math/rev/core/operator_plus_equal.hpp>
#include <stan/math/rev/core/operator_minus_equal.hpp>
#include <stan/math/rev/core/vv_vari.hpp>
#include <stan/math/rev/core/vd_vari.hpp>
#include <stan/math/prim/core/operator_multiplication.hpp>
#include <stan/math/prim/fun/constants.hpp>
#include <stan/math/prim/fun/is_any_nan.hpp>
#include <stan/math/prim/fun/isinf.hpp>
Expand Down Expand Up @@ -112,6 +117,45 @@ inline var operator*(Arith a, const var& b) {
return {new internal::multiply_vd_vari(b.vi_, a)}; // by symmetry
}

/**
* Return the product of std::complex<var> arguments.
*
* @param[in] x first argument
* @param[in] y second argument
* @return product of arguments
*/
inline std::complex<stan::math::var> operator*(
const std::complex<stan::math::var>& x,
const std::complex<stan::math::var>& y) {
return internal::complex_multiply(x, y);
}

/**
* Return the product of std::complex<double> and
* std::complex<var> arguments.
*
* @param[in] x first argument
* @param[in] y second argument
* @return product of arguments
*/
inline std::complex<stan::math::var> operator*(
const std::complex<double>& x, const std::complex<stan::math::var>& y) {
return internal::complex_multiply(x, y);
}

/**
* Return the product of std::complex<double> and
* std::complex<var> arguments.
*
* @param[in] x first argument
* @param[in] y second argument
* @return product of arguments
*/
inline std::complex<stan::math::var> operator*(
const std::complex<stan::math::var>& x, const std::complex<double>& y) {
return internal::complex_multiply(x, y);
}

} // namespace math
} // namespace stan
#endif