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

Encapsulate std::complex functions #3122

Merged
merged 22 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f87e167
testing encapsulation of std complex
SteveBronder Nov 5, 2024
2f225e2
fix all headers in rev
SteveBronder Nov 6, 2024
68c3681
add docs for all new functions
SteveBronder Nov 7, 2024
58fdd14
fix conj
SteveBronder Nov 7, 2024
1968994
fix complex conj
SteveBronder Nov 7, 2024
d0b650c
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Nov 8, 2024
c7892d6
fix double header includes
SteveBronder Nov 8, 2024
cd54411
fix docs
SteveBronder Nov 8, 2024
37a5e71
update fwd includes
SteveBronder Nov 11, 2024
83cf7d7
update includes for fwd to always prefer fwd version before prim vers…
SteveBronder Nov 11, 2024
c15aeae
update includes for fwd to always prefer fwd version before prim vers…
SteveBronder Nov 11, 2024
9a6a4ec
Docstring duplication and edits
WardBrian Nov 14, 2024
2bc815c
update header includes
SteveBronder Nov 14, 2024
7bc6c81
Merge commit '4a812be023c2b98c4ef97999985fd947cfc895fa' into HEAD
yashikno Nov 14, 2024
754547c
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Nov 14, 2024
d6ff92d
update header includes
SteveBronder Nov 14, 2024
a289886
fix headers
SteveBronder Nov 15, 2024
a0f26b8
Merge remote-tracking branch 'origin/develop' into fix/encapsulate-st…
SteveBronder Nov 15, 2024
4c84cfb
update headers
SteveBronder Nov 15, 2024
65770d7
update headers
SteveBronder Nov 15, 2024
8b26bc5
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Nov 15, 2024
7cf039a
cpplint fix
WardBrian Nov 15, 2024
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
4 changes: 2 additions & 2 deletions stan/math/fwd/fun/Phi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/fun/pow.hpp>
#include <stan/math/fwd/fun/exp.hpp>
#include <stan/math/prim/fun/constants.hpp>
#include <stan/math/prim/fun/Phi.hpp>
#include <cmath>
Expand All @@ -12,8 +14,6 @@ namespace math {

template <typename T>
inline fvar<T> Phi(const fvar<T>& x) {
using std::exp;
using std::sqrt;
T xv = x.val_;
return fvar<T>(Phi(xv), x.d_ * exp(xv * xv / -2.0) * INV_SQRT_TWO_PI);
}
Expand Down
5 changes: 3 additions & 2 deletions stan/math/fwd/fun/Phi_approx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/prim/fun/inv_logit.hpp>
#include <stan/math/fwd/fun/inv_logit.hpp>
#include <stan/math/fwd/fun/pow.hpp>
#include <stan/math/prim/fun/Phi_approx.hpp>
#include <cmath>

namespace stan {
Expand All @@ -21,7 +23,6 @@ namespace math {
*/
template <typename T>
inline fvar<T> Phi_approx(const fvar<T>& x) {
using std::pow;
return inv_logit(0.07056 * pow(x, 3.0) + 1.5976 * x);
}

Expand Down
4 changes: 2 additions & 2 deletions stan/math/fwd/fun/abs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/prim/fun/abs.hpp>
#include <stan/math/fwd/fun/value_of.hpp>
#include <stan/math/prim/fun/constants.hpp>
#include <stan/math/prim/fun/value_of.hpp>
#include <stan/math/prim/fun/abs.hpp>
#include <complex>

namespace stan {
Expand Down
5 changes: 2 additions & 3 deletions stan/math/fwd/fun/acos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/meta.hpp>
#include <stan/math/prim/fun/square.hpp>
#include <stan/math/fwd/fun/sqrt.hpp>
#include <stan/math/fwd/fun/square.hpp>
#include <stan/math/prim/fun/acos.hpp>
#include <cmath>
#include <complex>
Expand All @@ -13,8 +14,6 @@ namespace math {

template <typename T>
inline fvar<T> acos(const fvar<T>& x) {
using std::acos;
using std::sqrt;
return fvar<T>(acos(x.val_), x.d_ / -sqrt(1 - square(x.val_)));
}

Expand Down
5 changes: 2 additions & 3 deletions stan/math/fwd/fun/acosh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/fun/sqrt.hpp>
#include <stan/math/fwd/fun/square.hpp>
#include <stan/math/prim/fun/acosh.hpp>
#include <stan/math/prim/fun/square.hpp>
#include <stan/math/prim/fun/sqrt.hpp>
#include <cmath>
#include <complex>

Expand All @@ -14,7 +14,6 @@ namespace math {

template <typename T>
inline fvar<T> acosh(const fvar<T>& x) {
using std::sqrt;
return fvar<T>(acosh(x.val_), x.d_ / sqrt(square(x.val_) - 1));
}

Expand Down
5 changes: 2 additions & 3 deletions stan/math/fwd/fun/asin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/fun/sqrt.hpp>
#include <stan/math/fwd/fun/square.hpp>
#include <stan/math/prim/fun/asin.hpp>
#include <stan/math/prim/fun/square.hpp>
#include <cmath>
#include <complex>

Expand All @@ -13,8 +14,6 @@ namespace math {

template <typename T>
inline fvar<T> asin(const fvar<T>& x) {
using std::asin;
using std::sqrt;
return fvar<T>(asin(x.val_), x.d_ / sqrt(1 - square(x.val_)));
}

Expand Down
4 changes: 2 additions & 2 deletions stan/math/fwd/fun/asinh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/fun/sqrt.hpp>
#include <stan/math/fwd/fun/square.hpp>
#include <stan/math/prim/fun/asinh.hpp>
#include <stan/math/prim/fun/square.hpp>
#include <cmath>
#include <complex>

Expand All @@ -13,7 +14,6 @@ namespace math {

template <typename T>
inline fvar<T> asinh(const fvar<T>& x) {
using std::sqrt;
return fvar<T>(asinh(x.val_), x.d_ / sqrt(square(x.val_) + 1));
}

Expand Down
4 changes: 2 additions & 2 deletions stan/math/fwd/fun/atan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/fun/atanh.hpp>
#include <stan/math/fwd/fun/square.hpp>
#include <stan/math/prim/fun/atan.hpp>
#include <stan/math/prim/fun/square.hpp>
#include <cmath>
#include <complex>

Expand All @@ -13,7 +14,6 @@ namespace math {

template <typename T>
inline fvar<T> atan(const fvar<T>& x) {
using std::atan;
return fvar<T>(atan(x.val_), x.d_ / (1 + square(x.val_)));
}

Expand Down
6 changes: 2 additions & 4 deletions stan/math/fwd/fun/atan2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,28 @@

#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/prim/fun/square.hpp>
#include <stan/math/fwd/fun/square.hpp>
WardBrian marked this conversation as resolved.
Show resolved Hide resolved
#include <stan/math/prim/fun/atan2.hpp>
#include <cmath>

namespace stan {
namespace math {

template <typename T>
inline fvar<T> atan2(const fvar<T>& x1, const fvar<T>& x2) {
using std::atan2;
return fvar<T>(atan2(x1.val_, x2.val_),
(x1.d_ * x2.val_ - x1.val_ * x2.d_)
/ (square(x2.val_) + square(x1.val_)));
}

template <typename T>
inline fvar<T> atan2(double x1, const fvar<T>& x2) {
using std::atan2;
return fvar<T>(atan2(x1, x2.val_),
(-x1 * x2.d_) / (square(x1) + square(x2.val_)));
}

template <typename T>
inline fvar<T> atan2(const fvar<T>& x1, double x2) {
using std::atan2;
return fvar<T>(atan2(x1.val_, x2),
(x1.d_ * x2) / (square(x2) + square(x1.val_)));
}
Expand Down
4 changes: 3 additions & 1 deletion stan/math/fwd/fun/atanh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/fun/log.hpp>
#include <stan/math/fwd/fun/square.hpp>
#include <stan/math/fwd/fun/value_of_rec.hpp>
#include <stan/math/prim/fun/atanh.hpp>
#include <stan/math/prim/fun/square.hpp>
#include <cmath>
#include <complex>

Expand Down
2 changes: 1 addition & 1 deletion stan/math/fwd/fun/beta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/fun/digamma.hpp>
#include <stan/math/prim/fun/beta.hpp>
#include <stan/math/prim/fun/digamma.hpp>

namespace stan {
namespace math {
Expand Down
2 changes: 1 addition & 1 deletion stan/math/fwd/fun/cbrt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/fun/square.hpp>
#include <stan/math/prim/fun/cbrt.hpp>
#include <stan/math/prim/fun/square.hpp>

namespace stan {
namespace math {
Expand Down
2 changes: 1 addition & 1 deletion stan/math/fwd/fun/ceil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/prim/fun/ceil.hpp>
#include <cmath>

namespace stan {
namespace math {

template <typename T>
inline fvar<T> ceil(const fvar<T>& x) {
using std::ceil;
return fvar<T>(ceil(x.val_), 0);
}

Expand Down
18 changes: 0 additions & 18 deletions stan/math/fwd/fun/conj.hpp
WardBrian marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,4 @@
#include <stan/math/prim/fun/conj.hpp>
#include <complex>

namespace stan {
namespace math {

/**
* Return the phase angle of the complex argument.
*
* @tparam T value type of autodiff variable
* @param[in] z argument
* @return phase angle of the argument
*/
template <typename T>
inline std::complex<fvar<T>> conj(const std::complex<fvar<T>>& z) {
return internal::complex_conj(z);
}

} // namespace math
} // namespace stan

#endif
4 changes: 2 additions & 2 deletions stan/math/fwd/fun/cos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/fun/sin.hpp>
#include <stan/math/fwd/fun/cosh.hpp>
#include <stan/math/prim/fun/cos.hpp>
#include <cmath>
#include <complex>
Expand All @@ -12,8 +14,6 @@ namespace math {

template <typename T>
inline fvar<T> cos(const fvar<T>& x) {
using std::cos;
using std::sin;
return fvar<T>(cos(x.val_), x.d_ * -sin(x.val_));
}

Expand Down
3 changes: 1 addition & 2 deletions stan/math/fwd/fun/cosh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/fun/exp.hpp>
#include <stan/math/fwd/fun/sinh.hpp>
#include <stan/math/prim/fun/cosh.hpp>
#include <cmath>
#include <complex>
Expand All @@ -13,8 +14,6 @@ namespace math {

template <typename T>
inline fvar<T> cosh(const fvar<T>& x) {
using std::cosh;
using std::sinh;
return fvar<T>(cosh(x.val_), x.d_ * sinh(x.val_));
}

Expand Down
4 changes: 2 additions & 2 deletions stan/math/fwd/fun/determinant.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef STAN_MATH_FWD_FUN_DETERMINANT_HPP
#define STAN_MATH_FWD_FUN_DETERMINANT_HPP

#include <stan/math/prim/fun/Eigen.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/prim/meta.hpp>
#include <stan/math/prim/err.hpp>
#include <stan/math/prim/fun/Eigen.hpp>
#include <stan/math/prim/fun/to_ref.hpp>
#include <stan/math/fwd/core.hpp>

namespace stan {
namespace math {
Expand Down
2 changes: 1 addition & 1 deletion stan/math/fwd/fun/digamma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/fun/trigamma.hpp>

#include <stan/math/prim/fun/digamma.hpp>
#include <stan/math/prim/fun/trigamma.hpp>

namespace stan {
namespace math {
Expand Down
4 changes: 2 additions & 2 deletions stan/math/fwd/fun/erf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/fun/exp.hpp>
#include <stan/math/fwd/fun/square.hpp>
#include <stan/math/prim/fun/constants.hpp>
#include <stan/math/prim/fun/erf.hpp>
#include <stan/math/prim/fun/square.hpp>
#include <cmath>

namespace stan {
namespace math {

template <typename T>
inline fvar<T> erf(const fvar<T>& x) {
using std::exp;
return fvar<T>(erf(x.val_), x.d_ * exp(-square(x.val_)) * TWO_OVER_SQRT_PI);
}

Expand Down
4 changes: 2 additions & 2 deletions stan/math/fwd/fun/erfc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/fun/exp.hpp>
#include <stan/math/fwd/fun/square.hpp>
#include <stan/math/prim/fun/constants.hpp>
#include <stan/math/prim/fun/erfc.hpp>
#include <stan/math/prim/fun/square.hpp>
#include <cmath>

namespace stan {
namespace math {

template <typename T>
inline fvar<T> erfc(const fvar<T>& x) {
using std::exp;
return fvar<T>(erfc(x.val_), -x.d_ * exp(-square(x.val_)) * TWO_OVER_SQRT_PI);
}

Expand Down
3 changes: 2 additions & 1 deletion stan/math/fwd/fun/exp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/fun/cos.hpp>
#include <stan/math/fwd/fun/sin.hpp>
#include <stan/math/prim/fun/exp.hpp>
#include <cmath>
#include <complex>
Expand All @@ -11,7 +13,6 @@ namespace stan {
namespace math {
template <typename T>
inline fvar<T> exp(const fvar<T>& x) {
using std::exp;
return fvar<T>(exp(x.val_), x.d_ * exp(x.val_));
}

Expand Down
2 changes: 1 addition & 1 deletion stan/math/fwd/fun/exp2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/prim/fun/exp2.hpp>
#include <stan/math/prim/fun/constants.hpp>
#include <stan/math/prim/fun/exp2.hpp>
#include <cmath>

namespace stan {
Expand Down
4 changes: 2 additions & 2 deletions stan/math/fwd/fun/expm1.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#ifndef STAN_MATH_FWD_FUN_EXPM1_HPP
#define STAN_MATH_FWD_FUN_EXPM1_HPP

#include <stan/math/prim/fun/expm1.hpp>
#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/fun/exp.hpp>
#include <stan/math/prim/fun/expm1.hpp>
#include <cmath>

namespace stan {
namespace math {

template <typename T>
inline fvar<T> expm1(const fvar<T>& x) {
using std::exp;
return fvar<T>(expm1(x.val_), x.d_ * exp(x.val_));
}

Expand Down
Loading