Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
assign.hpp
Go to the documentation of this file.
1 #ifndef STAN__MATH__MATRIX__ASSIGN_HPP
2 #define STAN__MATH__MATRIX__ASSIGN_HPP
3 
4 #include <vector>
5 #include <sstream>
6 #include <stdexcept>
7 
11 
12 
13 #include <iostream>
14 
15 namespace stan {
16 
17  namespace math {
18 
19  // Recursive assignment with size match checking and promotion
20 
35  template <typename LHS, typename RHS>
36  inline void
37  assign(LHS& lhs, const RHS& rhs) {
38  lhs = rhs;
39  }
40 
61  template <typename LHS, typename RHS, int R1, int C1, int R2, int C2>
62  inline void
63  assign(Eigen::Matrix<LHS,R1,C1>& x,
64  const Eigen::Matrix<RHS,R2,C2>& y) {
65  std::stringstream ss;
66  ss << "error in call to assign(Eigen::Matrix,Eigen::Matrix)"
67  << "; shapes must match, but found"
68  << " R1=" << R1
69  << "; C1=" << C1
70  << "; R2=" << R2
71  << "; C2=" << C2;
72  throw std::domain_error(ss.str());
73  }
74 
92  template <typename LHS, typename RHS, int R, int C>
93  inline void
94  assign(Eigen::Matrix<LHS,R,C>& x,
95  const Eigen::Matrix<RHS,R,C>& y) {
96  stan::math::check_matching_dims("assign(%1%)",x,"x",
97  y,"y",(double*)0);
98  for (int i = 0; i < x.size(); ++i)
99  assign(x(i),y(i));
100  }
101 
120  template <typename LHS, typename RHS, int R, int C>
121  inline void
122  assign(Eigen::Block<LHS> x,
123  const Eigen::Matrix<RHS,R,C>& y) {
124  stan::math::check_matching_sizes("assign(%1%)",x,"x",
125  y,"y",(double*)0);
126  for (int n = 0; n < y.cols(); ++n)
127  for (int m = 0; m < y.rows(); ++m)
128  assign(x(m,n),y(m,n));
129  }
130 
131 
151  template <typename LHS, typename RHS>
152  inline void
153  assign(std::vector<LHS>& x, const std::vector<RHS>& y) {
154  stan::math::check_matching_sizes("assign(%1%)",x,"x",
155  y,"y",(double*)0);
156  for (size_t i = 0; i < x.size(); ++i)
157  assign(x[i],y[i]);
158  }
159 
160 
161  }
162 }
163 #endif
bool check_matching_dims(const char *function, const Eigen::Matrix< T1, R1, C1 > &y1, const char *name1, const Eigen::Matrix< T2, R2, C2 > &y2, const char *name2, T_result *result)
void assign(LHS &lhs, const RHS &rhs)
Copy the right-hand side's value to the left-hand side variable.
Definition: assign.hpp:37
bool check_matching_sizes(const char *function, const T_y1 &y1, const char *name1, const T_y2 &y2, const char *name2, T_result *result)

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