Skip to content

Commit

Permalink
Merge branch 'cleanup/require_base' of github.com:stan-dev/math into …
Browse files Browse the repository at this point in the history
…cleanup/require_base
  • Loading branch information
SteveBronder committed Mar 28, 2020
2 parents ca861a5 + 169f47d commit 878d3f4
Show file tree
Hide file tree
Showing 139 changed files with 3,377 additions and 168 deletions.
2 changes: 1 addition & 1 deletion make/compiler_flags
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Find files subroutine for different operating system
# This is recursive version of the makefiles wildcard function
findfiles = $(subst \n,,$(foreach d,$(wildcard $(addsuffix *,$(1))),$(call findfiles,$(d)/,$(2)) $(wildcard $(d)/$(2))))
findfiles = $(strip $(subst \n,,$(foreach d,$(wildcard $(addsuffix *,$(1))),$(call findfiles,$(d)/,$(2)) $(wildcard $(d)/$(2)))))

ifneq ($(OS),Windows_NT)
GENERATE_DISTRIBUTION_TESTS=true
Expand Down
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);
}
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

0 comments on commit 878d3f4

Please sign in to comment.