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 9 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: 1 addition & 3 deletions stan/math/fwd/fun/acos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/meta.hpp>
#include <stan/math/prim/fun/square.hpp>
#include <stan/math/fwd/fun/square.hpp>
#include <stan/math/prim/fun/acos.hpp>
#include <cmath>
#include <complex>
Expand All @@ -13,8 +13,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/square.hpp>
#include <stan/math/fwd/fun/sqrt.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/square.hpp>
#include <stan/math/fwd/fun/sqrt.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
3 changes: 1 addition & 2 deletions stan/math/fwd/fun/asinh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/meta.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 +13,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
3 changes: 1 addition & 2 deletions stan/math/fwd/fun/atan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/meta.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 +13,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
5 changes: 1 addition & 4 deletions stan/math/fwd/fun/atan2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,27 @@

#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 <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
2 changes: 1 addition & 1 deletion stan/math/fwd/fun/atanh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/fun/square.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
1 change: 0 additions & 1 deletion stan/math/fwd/fun/ceil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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
3 changes: 1 addition & 2 deletions stan/math/fwd/fun/cos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/fun/sin.hpp>
#include <stan/math/prim/fun/cos.hpp>
#include <cmath>
#include <complex>
Expand All @@ -12,8 +13,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
2 changes: 1 addition & 1 deletion stan/math/fwd/fun/erf.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/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 {
Expand Down
2 changes: 1 addition & 1 deletion stan/math/fwd/fun/inv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#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>

namespace stan {
namespace math {
Expand Down
1 change: 1 addition & 0 deletions stan/math/fwd/fun/inv_sqrt.hpp
WardBrian marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

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

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

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

Expand Down
5 changes: 2 additions & 3 deletions stan/math/fwd/fun/sinh.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#ifndef STAN_MATH_FWD_FUN_SINH_HPP
#define STAN_MATH_FWD_FUN_SINH_HPP

#include <stan/math/prim/fun/sinh.hpp>
#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/fun/cosh.hpp>
#include <stan/math/prim/fun/sinh.hpp>
#include <complex>

namespace stan {
namespace math {

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

Expand Down
2 changes: 1 addition & 1 deletion stan/math/fwd/fun/softmax.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef STAN_MATH_FWD_FUN_SOFTMAX_HPP
#define STAN_MATH_FWD_FUN_SOFTMAX_HPP

#include <stan/math/prim/fun/Eigen.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/fun/value_of.hpp>
#include <stan/math/prim/fun/Eigen.hpp>
#include <stan/math/prim/fun/softmax.hpp>
#include <stan/math/prim/fun/to_ref.hpp>
#include <stan/math/prim/fun/value_of.hpp>
Expand Down
5 changes: 1 addition & 4 deletions stan/math/fwd/fun/sqrt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

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

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

template <typename T>
inline fvar<T> sqrt(const fvar<T>& x) {
using std::sqrt;
if (value_of_rec(x.val_) == 0.0) {
return fvar<T>(sqrt(x.val_), 0.0 * x.d_);
}
Expand Down
3 changes: 1 addition & 2 deletions stan/math/fwd/fun/tan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/fun/tan.hpp>
WardBrian marked this conversation as resolved.
Show resolved Hide resolved
#include <stan/math/prim/fun/tan.hpp>
#include <cmath>
#include <complex>
Expand All @@ -12,8 +13,6 @@ namespace math {

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

Expand Down
1 change: 0 additions & 1 deletion stan/math/fwd/fun/tanh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace math {

template <typename T>
inline fvar<T> tanh(const fvar<T>& x) {
using std::tanh;
T u = tanh(x.val_);
return fvar<T>(u, x.d_ * (1 - u * u));
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/mix/fun/typedefs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define STAN_MATH_MIX_MAT_FUN_TYPEDEFS_HPP

#include <stan/math/prim/fun/Eigen.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/rev/core.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/fun/Eigen_NumTraits.hpp>

namespace stan {
Expand Down
2 changes: 1 addition & 1 deletion stan/math/mix/functor/derivative.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef STAN_MATH_MIX_FUNCTOR_DERIVATIVE_HPP
#define STAN_MATH_MIX_FUNCTOR_DERIVATIVE_HPP

#include <stan/math/rev/core.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/prim/fun/Eigen.hpp>
#include <stan/math/rev/core.hpp>
#include <vector>

namespace stan {
Expand Down
2 changes: 1 addition & 1 deletion stan/math/mix/functor/finite_diff_grad_hessian_auto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#define STAN_MATH_MIX_FUNCTOR_FINITE_DIFF_GRAD_HESSIAN_AUTO_HPP

#include <stan/math/prim/fun/Eigen.hpp>
#include <stan/math/prim/functor/finite_diff_gradient_auto.hpp>
#include <stan/math/rev/core.hpp>
#include <stan/math/mix/functor/hessian.hpp>
#include <stan/math/prim/functor/finite_diff_gradient_auto.hpp>
#include <vector>

namespace stan {
Expand Down
2 changes: 1 addition & 1 deletion stan/math/mix/functor/grad_hessian.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef STAN_MATH_MIX_FUNCTOR_GRAD_HESSIAN_HPP
#define STAN_MATH_MIX_FUNCTOR_GRAD_HESSIAN_HPP

#include <stan/math/rev/core.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/prim/fun/Eigen.hpp>
#include <stan/math/rev/core.hpp>
#include <stdexcept>
#include <vector>

Expand Down
4 changes: 2 additions & 2 deletions stan/math/mix/functor/grad_tr_mat_times_hessian.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef STAN_MATH_MIX_FUNCTOR_GRAD_TR_MAT_TIMES_HESSIAN_HPP
#define STAN_MATH_MIX_FUNCTOR_GRAD_TR_MAT_TIMES_HESSIAN_HPP

#include <stan/math/mix/functor/gradient_dot_vector.hpp>
#include <stan/math/rev/core.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/prim/fun/Eigen.hpp>
#include <stan/math/rev/core.hpp>
#include <stan/math/mix/functor/gradient_dot_vector.hpp>
#include <stdexcept>
#include <vector>

Expand Down
Loading