Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
assign.hpp
Go to the documentation of this file.
1 #ifndef __STAN__AGRAD__REV__MATRIX__ASSIGN_HPP__
2 #define __STAN__AGRAD__REV__MATRIX__ASSIGN_HPP__
3 
4 #include <vector>
5 #include <boost/math/tools/promotion.hpp>
8 #include <stan/agrad/rev/var.hpp>
12 #include <stan/meta/traits.hpp>
13 
14 namespace stan {
15  namespace agrad {
16 
17  namespace {
18  template <typename LHS, typename RHS>
19  struct needs_promotion {
20  enum { value = ( is_constant_struct<RHS>::value
21  && !is_constant_struct<LHS>::value) };
22  };
23 
24  template <bool PromoteRHS, typename LHS, typename RHS>
25  struct assigner {
26  static inline void assign(LHS& /*var*/, const RHS& /*val*/) {
27  throw std::domain_error("should not call base class of assigner");
28  }
29  };
30 
31  template <typename LHS, typename RHS>
32  struct assigner<false,LHS,RHS> {
33  static inline void assign(LHS& var, const RHS& val) {
34  var = val; // no promotion of RHS
35  }
36  };
37 
38  template <typename LHS, typename RHS>
39  struct assigner<true,LHS,RHS> {
40  static inline void assign(LHS& var, const RHS& val) {
41  assign_to_var(var,val); // promote RHS
42  }
43  };
44  }
45 
46  template <typename LHS, typename RHS>
47  inline void assign(Eigen::Block<LHS> var, const RHS& val) {
48  assigner<needs_promotion<Eigen::Block<LHS>,RHS>::value, Eigen::Block<LHS>, RHS>::assign(var,val);
49  }
50 
51  template <typename LHS, typename RHS>
52  inline void assign(LHS& var, const RHS& val) {
53  assigner<needs_promotion<LHS,RHS>::value, LHS, RHS>::assign(var,val);
54  }
55 
56  }
57 }
58 #endif

     [ Stan Home Page ] © 2011–2013, Stan Development Team.