Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
c00158f
exp, copysign, complex test extensions
Mar 1, 2020
f715f51
i_times and related
Mar 1, 2020
b83e006
Merge branch 'develop' of https://github.com/stan-dev/math into featu…
Mar 1, 2020
d64babe
complex binary operator+ and operator-
Mar 2, 2020
4b07ef7
complex operator/ and operator*
Mar 2, 2020
a4ee58a
complex unary operator+ and operator-
Mar 2, 2020
e010c0c
complex operator== and operator!=
Mar 2, 2020
46e822a
complex imag and real functions
Mar 4, 2020
3148153
asinh, but won't pass until log etc in
Mar 4, 2020
472641c
complex abs
Mar 4, 2020
159ac31
complex arg function
Mar 4, 2020
b01f01f
Merge branch 'develop' of https://github.com/stan-dev/math into featu…
bob-carpenter Mar 5, 2020
15de802
complex norm and arg
bob-carpenter Mar 5, 2020
313f8c9
complex conj
bob-carpenter Mar 5, 2020
b2ff01a
complex proj
bob-carpenter Mar 5, 2020
7298cd6
complex exp
bob-carpenter Mar 5, 2020
aa4c2cd
complex sqrt
bob-carpenter Mar 5, 2020
a17575e
complex log
bob-carpenter Mar 5, 2020
3118b03
complex log10
bob-carpenter Mar 5, 2020
6195984
complex pow
bob-carpenter Mar 5, 2020
04f0606
complex sinh
bob-carpenter Mar 5, 2020
f4e6fd7
Merge branch 'develop' of https://github.com/stan-dev/math into featu…
bob-carpenter Mar 5, 2020
d243df4
complex cosh
bob-carpenter Mar 5, 2020
8ea8a75
logb, scalbn and complex tanh
bob-carpenter Mar 6, 2020
c54ec0b
Merge branch 'develop' of https://github.com/stan-dev/math into featu…
bob-carpenter Mar 10, 2020
8620d47
complex operator/
bob-carpenter Mar 10, 2020
29a8bf6
complex sin
bob-carpenter Mar 10, 2020
77cdad1
complex cosine
bob-carpenter Mar 10, 2020
5095a24
complex tan
bob-carpenter Mar 10, 2020
673c4fc
complex asinh, acosh
bob-carpenter Mar 10, 2020
654717d
complex atanh
bob-carpenter Mar 10, 2020
5d4bad1
complex asin
bob-carpenter Mar 10, 2020
13a1e39
complex acos
bob-carpenter Mar 10, 2020
606a3c3
complex atan
bob-carpenter Mar 10, 2020
ba8100a
complex polar, still not passing with int args
bob-carpenter Mar 10, 2020
01fb26a
complex polar tests componentwise
Mar 11, 2020
c69263a
cpplint include and spacing fixes
Mar 11, 2020
e376d6a
fix merge after qr removal on develop
Mar 11, 2020
971337c
header include fixes, part 1 of many
Mar 11, 2020
d25c1f9
complex trig includes for headers
Mar 11, 2020
ef72d1c
complex updates passing header tests
Mar 11, 2020
fffa169
Merge branch 'develop' of https://github.com/stan-dev/math into featu…
Mar 11, 2020
19dbc28
overloads for g++; remove complex in complex in test
Mar 11, 2020
6563272
doxygen arg cleanup
Mar 11, 2020
eb16b34
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Mar 11, 2020
ea25a8e
moved rev includes to rev for complex acos
Mar 11, 2020
e4e1332
Merge branch 'feature/0123-complex-funs' of https://github.com/stan-d…
Mar 11, 2020
05596a5
include operator_equal and complex var
Mar 11, 2020
16788e2
includes for complex for g++ header tests
Mar 12, 2020
de9a53e
inline complex polar function
Mar 12, 2020
9e11c95
remove unused var(std::complex) ctor and tests
Mar 12, 2020
7b0a3e2
add using signbit in test
Mar 12, 2020
5f3267c
include std::abs for abs test
Mar 12, 2020
e13f3f3
resolve merge conflict in cosh
Mar 23, 2020
f7b41da
extended expect_near_rel to complex
Mar 23, 2020
508fbc2
added doc for logb
Mar 23, 2020
5b24cda
use signbit instead of comparison for copysign
Mar 23, 2020
657b9d3
added test cases and removed dead comments
Mar 23, 2020
4af9783
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Mar 23, 2020
c254454
rev copysign includes
Mar 23, 2020
442ac3b
Merge branch 'feature/0123-complex-funs' of https://github.com/stan-d…
Mar 23, 2020
2ddec40
removed unnecessary constructor
Mar 23, 2020
7f13bfb
copysign boundary conditions
Mar 23, 2020
b826430
Merge branch 'develop' of https://github.com/stan-dev/math into featu…
Mar 23, 2020
492b26c
remove unused code and comments
Mar 24, 2020
9829029
tests for complex ==, != w. framework
Mar 24, 2020
779dc95
doc for complex comparison test
Mar 25, 2020
830941d
Merge branch 'develop' of https://github.com/stan-dev/math into featu…
Mar 25, 2020
e04365d
resolve pow(complex<T>, int) ambiguity in gcc from C++99
Mar 26, 2020
b4bccc9
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Mar 26, 2020
c6bd5d7
Merge branch 'develop' of https://github.com/stan-dev/math into featu…
Mar 27, 2020
1a64c9a
MINGW32-specific overload resolving pow(double, int) ambiguity
Mar 28, 2020
1bd2ba9
Merge branch 'feature/0123-complex-funs' of https://github.com/stan-d…
Mar 28, 2020
d430f80
Made mingw implementation of pow inline (issue #123)
bbbales2 Mar 28, 2020
06b15fd
[Jenkins] auto-formatting by clang-format version 5.0.0-3~16.04.1 (ta…
stan-buildbot Mar 28, 2020
1fce197
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Mar 28, 2020
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
61 changes: 56 additions & 5 deletions stan/math/fwd/core/operator_division.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#define STAN_MATH_FWD_CORE_OPERATOR_DIVISION_HPP

#include <stan/math/fwd/core/fvar.hpp>
#include <stan/math/prim/core/operator_division.hpp>
#include <complex>
#include <type_traits>

namespace stan {
namespace math {
Expand All @@ -28,8 +31,8 @@ inline fvar<T> operator/(const fvar<T>& x1, const fvar<T>& x2) {
* @param x2 second argument
* @return first argument divided by second argument
*/
template <typename T>
inline fvar<T> operator/(const fvar<T>& x1, double x2) {
template <typename T, typename U, require_arithmetic_t<U>...>
inline fvar<T> operator/(const fvar<T>& x1, U x2) {
return fvar<T>(x1.val_ / x2, x1.d_ / x2);
}

Expand All @@ -41,11 +44,59 @@ inline fvar<T> operator/(const fvar<T>& x1, double x2) {
* @param x2 second argument
* @return first argument divided by second argument
*/
template <typename T>
inline fvar<T> operator/(double x1, const fvar<T>& x2) {
// TODO(carpenter): store x1 / x2.val_ and reuse
template <typename T, typename U, require_arithmetic_t<U>...>
inline fvar<T> operator/(U x1, const fvar<T>& x2) {
return fvar<T>(x1 / x2.val_, -x1 * x2.d_ / (x2.val_ * x2.val_));
}

template <typename T>
inline std::complex<fvar<T>> operator/(const std::complex<fvar<T>>& x1,
const std::complex<fvar<T>>& x2) {
return internal::complex_divide(x1, x2);
}
Comment thread
bob-carpenter marked this conversation as resolved.
template <typename T, typename U, require_arithmetic_t<U>...>
inline std::complex<fvar<T>> operator/(const std::complex<fvar<T>>& x1,
const std::complex<U>& x2) {
return internal::complex_divide(x1, x2);
}
template <typename T>
inline std::complex<fvar<T>> operator/(const std::complex<fvar<T>>& x1,
const fvar<T>& x2) {
return internal::complex_divide(x1, x2);
}
template <typename T, typename U, require_arithmetic_t<U>...>
inline std::complex<fvar<T>> operator/(const std::complex<fvar<T>>& x1, U x2) {
return internal::complex_divide(x1, x2);
}

template <typename T, typename U, require_arithmetic_t<U>...>
inline std::complex<fvar<T>> operator/(const std::complex<U>& x1,
const std::complex<fvar<T>>& x2) {
return internal::complex_divide(x1, x2);
}
template <typename T, typename U, require_arithmetic_t<U>...>
inline std::complex<fvar<T>> operator/(const std::complex<U>& x1,
const fvar<T>& x2) {
return internal::complex_divide(x1, x2);
}

template <typename T>
inline std::complex<fvar<T>> operator/(const fvar<T>& x1,
const std::complex<fvar<T>>& x2) {
return internal::complex_divide(x1, x2);
}
template <typename T, typename U,
typename = std::enable_if_t<std::is_arithmetic<U>::value>>
inline std::complex<fvar<T>> operator/(const fvar<T>& x1,
const std::complex<U>& x2) {
return internal::complex_divide(x1, x2);
}

template <typename T, typename U, require_arithmetic_t<U>...>
inline std::complex<fvar<T>> operator/(U x1, const std::complex<fvar<T>>& x2) {
return internal::complex_divide(x1, x2);
}

} // namespace math
} // namespace stan
#endif
8 changes: 6 additions & 2 deletions stan/math/fwd/core/std_complex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ class complex<stan::math::fvar<T>>
* @tparam Scalar real type (must be assignable to `value_type`)
* @param[in] re real part
*/
template <typename U, typename = stan::require_stan_scalar_t<U>>
complex(U&& re) : base_t(re) {} // NOLINT(runtime/explicit)
template <typename U> // , typename = stan::require_stan_scalar_t<U>>
complex(const U& re) : base_t(re) {} // NOLINT(runtime/explicit)

template <typename U>
complex(const std::complex<U>& z) // NOLINT(runtime/explicit)
: base_t(z.real(), z.imag()) {}

/**
* Construct a complex number from the specified real and imaginary
Expand Down
5 changes: 5 additions & 0 deletions stan/math/fwd/fun.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <stan/math/fwd/fun/acos.hpp>
#include <stan/math/fwd/fun/acosh.hpp>
#include <stan/math/fwd/fun/asin.hpp>
#include <stan/math/fwd/fun/arg.hpp>
#include <stan/math/fwd/fun/asinh.hpp>
#include <stan/math/fwd/fun/atan.hpp>
#include <stan/math/fwd/fun/atan2.hpp>
Expand All @@ -15,6 +16,7 @@
#include <stan/math/fwd/fun/binary_log_loss.hpp>
#include <stan/math/fwd/fun/cbrt.hpp>
#include <stan/math/fwd/fun/ceil.hpp>
#include <stan/math/fwd/fun/conj.hpp>
#include <stan/math/fwd/fun/cos.hpp>
#include <stan/math/fwd/fun/cosh.hpp>
#include <stan/math/fwd/fun/determinant.hpp>
Expand Down Expand Up @@ -79,11 +81,14 @@
#include <stan/math/fwd/fun/multiply.hpp>
#include <stan/math/fwd/fun/multiply_log.hpp>
#include <stan/math/fwd/fun/multiply_lower_tri_self_transpose.hpp>
#include <stan/math/fwd/fun/norm.hpp>
#include <stan/math/fwd/fun/owens_t.hpp>
#include <stan/math/fwd/fun/Phi.hpp>
#include <stan/math/fwd/fun/Phi_approx.hpp>
#include <stan/math/fwd/fun/polar.hpp>
#include <stan/math/fwd/fun/pow.hpp>
#include <stan/math/fwd/fun/primitive_value.hpp>
#include <stan/math/fwd/fun/proj.hpp>
#include <stan/math/fwd/fun/quad_form.hpp>
#include <stan/math/fwd/fun/quad_form_sym.hpp>
#include <stan/math/fwd/fun/rising_factorial.hpp>
Expand Down
15 changes: 14 additions & 1 deletion stan/math/fwd/fun/abs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

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

namespace stan {
namespace math {
Expand All @@ -23,6 +24,18 @@ inline fvar<T> abs(const fvar<T>& x) {
}
}

/**
* Return the absolute value of the complex argument.
*
* @tparam T value type of argument
* @param[in] z argument
* @return absolute value of the argument
*/
template <typename T>
inline std::complex<fvar<T>> abs(const std::complex<fvar<T>>& z) {
return internal::complex_abs(z);
}

} // namespace math
} // namespace stan
#endif
17 changes: 16 additions & 1 deletion stan/math/fwd/fun/acos.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#ifndef STAN_MATH_FWD_FUN_ACOS_HPP
#define STAN_MATH_FWD_FUN_ACOS_HPP

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

namespace stan {
namespace math {
Expand All @@ -15,6 +17,19 @@ inline fvar<T> acos(const fvar<T>& x) {
using std::sqrt;
return fvar<T>(acos(x.val_), x.d_ / -sqrt(1 - square(x.val_)));
}

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

} // namespace math
} // namespace stan
#endif
14 changes: 14 additions & 0 deletions stan/math/fwd/fun/acosh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <stan/math/fwd/core.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>

namespace stan {
namespace math {
Expand All @@ -16,6 +18,18 @@ inline fvar<T> acosh(const fvar<T>& x) {
return fvar<T>(acosh(x.val_), x.d_ / sqrt(square(x.val_) - 1));
}

/**
* Return the hyperbolic arc cosine of the complex argument.
*
* @tparam T autodiff value type
* @param[in] z argument
* @return hyperbolic arc cosine of the argument
*/
template <typename T>
inline std::complex<fvar<T>> acosh(const std::complex<fvar<T>>& z) {
return internal::complex_acosh(z);
}

} // namespace math
} // namespace stan
#endif
26 changes: 26 additions & 0 deletions stan/math/fwd/fun/arg.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef STAN_MATH_FWD_FUN_ARG_HPP
#define STAN_MATH_FWD_FUN_ARG_HPP

#include <stan/math/fwd/core.hpp>
#include <stan/math/prim/fun/arg.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 fvar<T> arg(const std::complex<fvar<T>>& z) {
return internal::complex_arg(z);
}

} // namespace math
} // namespace stan

#endif
14 changes: 14 additions & 0 deletions stan/math/fwd/fun/asin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

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

namespace stan {
namespace math {
Expand All @@ -16,6 +18,18 @@ inline fvar<T> asin(const fvar<T>& x) {
return fvar<T>(asin(x.val_), x.d_ / sqrt(1 - square(x.val_)));
}

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

} // namespace math
} // namespace stan
#endif
15 changes: 14 additions & 1 deletion stan/math/fwd/fun/asinh.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#ifndef STAN_MATH_FWD_FUN_ASINH_HPP
#define STAN_MATH_FWD_FUN_ASINH_HPP

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

namespace stan {
namespace math {
Expand All @@ -16,6 +17,18 @@ inline fvar<T> asinh(const fvar<T>& x) {
return fvar<T>(asinh(x.val_), x.d_ / sqrt(square(x.val_) + 1));
}

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

} // namespace math
} // namespace stan
#endif
16 changes: 15 additions & 1 deletion stan/math/fwd/fun/atan.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#ifndef STAN_MATH_FWD_FUN_ATAN_HPP
#define STAN_MATH_FWD_FUN_ATAN_HPP

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

namespace stan {
namespace math {
Expand All @@ -15,6 +17,18 @@ inline fvar<T> atan(const fvar<T>& x) {
return fvar<T>(atan(x.val_), x.d_ / (1 + square(x.val_)));
}

/**
* Return the arc tangent of the complex argument.
*
* @tparam T autodiff value type
* @param[in] z argument
* @return arc tanget of the argument
*/
template <typename T>
inline std::complex<fvar<T>> atan(const std::complex<fvar<T>>& z) {
return internal::complex_atan(z);
}

} // namespace math
} // namespace stan
#endif
16 changes: 15 additions & 1 deletion stan/math/fwd/fun/atanh.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#ifndef STAN_MATH_FWD_FUN_ATANH_HPP
#define STAN_MATH_FWD_FUN_ATANH_HPP

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

namespace stan {
namespace math {
Expand All @@ -23,6 +25,18 @@ inline fvar<T> atanh(const fvar<T>& x) {
return fvar<T>(atanh(x.val_), x.d_ / (1 - square(x.val_)));
}

/**
* Return the hyperbolic arc tangent of the complex argument.
*
* @tparam T autodiff value type
* @param[in] z argument
* @return hyperbolic arc tangent of the argument
*/
template <typename T>
inline std::complex<fvar<T>> atanh(const std::complex<fvar<T>>& z) {
return internal::complex_atanh(z);
}

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