1 #ifndef STAN_MATH_REV_CORE_VAR_HPP 2 #define STAN_MATH_REV_CORE_VAR_HPP 7 #include <boost/math/tools/config.hpp> 18 static void grad(vari* vi);
154 : vi_(
new vari(static_cast<double>(x))) {}
193 explicit var(
const std::complex<double>&
x) {
195 vi_ =
new vari(real(x));
197 std::stringstream
ss;
198 ss <<
"Imaginary part of std::complex used to construct var" 199 <<
" must be zero. Found real part = " << real(x) <<
" and " 200 <<
" found imaginary part = " << imag(x) <<
std::endl;
214 explicit var(
const std::complex<float>&
x) {
216 vi_ =
new vari(static_cast<double>(real(x)));
218 std::stringstream
ss;
219 ss <<
"Imaginary part of std::complex used to construct var" 220 <<
" must be zero. Found real part = " << real(x) <<
" and " 221 <<
" found imaginary part = " << imag(x) <<
std::endl;
235 explicit var(
const std::complex<long double>&
x) {
237 vi_ =
new vari(static_cast<double>(real(x)));
239 std::stringstream
ss;
240 ss <<
"Imaginary part of std::complex used to construct var" 241 <<
" must be zero. Found real part = " << real(x) <<
" and " 242 <<
" found imaginary part = " << imag(x) <<
std::endl;
261 var(
size_t x) :
vi_(
new vari(static_cast<double>(x))) {}
270 var(ptrdiff_t x) :
vi_(
new vari(static_cast<double>(x))) {}
273 #ifdef BOOST_MATH_USE_FLOAT128 285 var(__float128 x) :
vi_(
new vari(static_cast<double>(x))) {}
294 inline double val()
const {
return vi_->
val_; }
304 inline double adj()
const {
return vi_->
adj_; }
318 void grad(std::vector<var>& x, std::vector<double>&
g) {
321 for (
size_t i = 0;
i < x.size(); ++
i)
473 if (v.
vi_ ==
nullptr)
474 return os <<
"uninitialized";
475 return os << v.
val();
var & operator+=(const var &b)
var & operator*=(const var &b)
var & operator/=(const var &b)
var(const std::complex< float > &x)
static void grad(vari *vi)
var & operator-=(const var &b)
var(const std::complex< double > &x)
void invalid_argument(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
void grad(std::vector< var > &x, std::vector< double > &g)
friend std::ostream & operator<<(std::ostream &os, const var &v)
var(const std::complex< long double > &x)