StanUtils.h
Go to the documentation of this file.
1 #pragma once
2 
3 /// \file StanUtils.h -- tools for use with Stan that don't have an obvious other home
4 
5 #ifndef DARWINBUILD
6 #include "Utilities/func/Stan.h"
7 #endif //DARWINBUILD
8 
9 class TH1;
10 
11 namespace util
12 {
13  // need a couple of functions so that we can
14  // always get the value in functions
15  // that are templated over both double and stan::math::var.
16 #ifndef DARWINBUILD
17  /// Either no-op or convert stan::math::var to double.
18  /// Exists so GetVal<T>(var) can be used with one signature inside a function templated over both stan::math::var & double.
19  /// (see, e.g., CAFAna/Fit/StanFitter.cxx.)
20  template <typename T>
21  inline T GetValAs(const stan::math::var &val);
22 
23  /// explicit specialization for double return value
24  template <>
25  inline double GetValAs(const stan::math::var &val) {return val.val();}
26 
27  /// explicit specialization for stan::math::var return value
28  template <>
29  inline stan::math::var GetValAs(const stan::math::var &val) { return val; }
30 #endif // DARWINBUILD
31 
32  /// Companion to GetValAs<>(stan::math::var) to provide ability to use GetValAs<double>(double)
33  /// without implicitly converting to a stan::math::var.
34  // (templated so that it respects the same convention as the one above)
35  template <typename T>
37 
38 #ifndef DARWINBUILD
39  /// Replacement for operator=() making it clear that you're 'casting' across double-stan::math::var boundary
40  inline void SetVal(double& target, const stan::math::var& source) {target = source.val();}
41  inline void SetVal(stan::math::var& target, const double& source) {target = source;}
42  inline void SetVal(stan::math::var& target, const stan::math::var& source) {target = source;}
43 #endif
44 
45  inline void SetVal(double& target, const double& source) {target = source;}
46 
47 }
void SetVal(double &target, const stan::math::var &source)
Replacement for operator=() making it clear that you&#39;re &#39;casting&#39; across double-stan::math::var bound...
Definition: StanUtils.h:40
Filter events based on their run/event numbers.
const XML_Char * target
Definition: expat.h:268
T GetValAs(const stan::math::var &val)
explicit specialization for double return value
Definition: StanUtils.h:25
const XML_Char int const XML_Char * value
Definition: expat.h:331
double T
Definition: Xdiff_gwt.C:5
double val() const
Definition: var.hpp:294