Automatic Differentiation
 
Loading...
Searching...
No Matches
conj.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_CONJ_HPP
2#define STAN_MATH_PRIM_FUN_CONJ_HPP
3
5#include <complex>
6
7namespace stan {
8namespace math {
9
17template <typename V, require_complex_bt<std::is_arithmetic, V>* = nullptr>
18inline auto conj(const V& z) {
19 return std::conj(z);
20}
21
29template <typename V, require_complex_bt<is_autodiff, V>* = nullptr>
30inline V conj(const V& z) {
31 return {z.real(), -z.imag()};
32}
33
42template <typename Eig, require_eigen_vt<is_complex, Eig>* = nullptr>
43inline auto conj(Eig&& z) {
44 return make_holder(
45 [](auto&& z_inner) {
46 return z_inner.unaryExpr([](auto&& z_i) { return conj(z_i); });
47 },
48 std::forward<Eig>(z));
49}
50
58template <typename StdVec, require_std_vector_st<is_complex, StdVec>* = nullptr>
59inline auto conj(const StdVec& z) {
60 const auto z_size = z.size();
61 promote_scalar_t<scalar_type_t<StdVec>, StdVec> result(z_size);
62 for (std::size_t i = 0; i < z_size; ++i) {
63 result[i] = conj(z[i]);
64 }
65 return result;
66}
67
68} // namespace math
69} // namespace stan
70
71#endif
auto make_holder(const F &func, Args &&... args)
Constructs an expression from given arguments using given functor.
Definition holder.hpp:352
typename promote_scalar_type< std::decay_t< T >, std::decay_t< S > >::type promote_scalar_t
auto conj(const V &z)
Return the complex conjugate the complex argument.
Definition conj.hpp:18
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...