Xped
Loading...
Searching...
No Matches
complex_vari.hpp
Go to the documentation of this file.
1#ifndef XPED_COMPLEX_VARI_HPP_
2#define XPED_COMPLEX_VARI_HPP_
3
4#include "stan/math/rev/core/vari.hpp"
5
6namespace stan::math {
7
8template <>
9class vari_value<std::complex<double>, void> : public vari_base
10{
11public:
12 using value_type = std::complex<double>;
16 const value_type val_;
21 value_type adj_{0.0, 0.0};
22
36 template <typename S, require_convertible_t<S&, std::complex<double>>* = nullptr>
37 vari_value(S x) noexcept
38 : val_(x)
39 { // NOLINT
40 ChainableStack::instance_->var_stack_.push_back(this);
41 }
42
58 template <typename S, require_convertible_t<S&, std::complex<double>>* = nullptr>
59 vari_value(S x, bool stacked) noexcept
60 : val_(x)
61 {
62 if(stacked) {
63 ChainableStack::instance_->var_stack_.push_back(this);
64 } else {
65 ChainableStack::instance_->var_nochain_stack_.push_back(this);
66 }
67 }
68
74 inline const auto& val() const { return val_; }
75
84 inline auto& adj() const { return adj_; }
85
94 inline auto& adj() { return adj_; }
95
96 inline void chain() {}
97
104 inline void init_dependent() noexcept { adj_ = {1.0, 0.0}; }
105
111 inline void set_zero_adjoint() noexcept final { adj_ = {0.0, 0.0}; }
112
122 friend std::ostream& operator<<(std::ostream& os, const vari_value<value_type>* v) { return os << v->val_ << ":" << v->adj_; }
123
124private:
125 template <typename, typename>
126 friend class var_value;
127};
128
129} // namespace stan::math
130
131#endif
std::ostream & operator<<(std::ostream &os, const FusionTree< depth, Symmetry > &tree)
Definition: FusionTree.hpp:93