| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
assign.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_ASSIGN_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_ASSIGN_HPP
3
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/prim/scal/err/invalid_argument.hpp>
6 #include <stan/math/prim/mat/err/check_matching_sizes.hpp>
7 #include <stan/math/prim/mat/err/check_matching_dims.hpp>
8 #include <iostream>
9 #include <sstream>
10 #include <stdexcept>
11 #include <string>
12 #include <vector>
13
14 namespace stan {
15
16 namespace math {
17
18 // Recursive assignment with size match checking and promotion
19
34 template <typename LHS, typename RHS>
35 inline void
36 assign(LHS& lhs, const RHS& rhs) {
37 lhs = rhs;
38 }
39
60 template <typename LHS, typename RHS, int R1, int C1, int R2, int C2>
61 inline void
62 assign(Eigen::Matrix<LHS, R1, C1>& x,
63 const Eigen::Matrix<RHS, R2, C2>& y) {
64 std::stringstream ss;
65 ss << "shapes must match, but found"
66 << " R1=" << R1
67 << "; C1=" << C1
68 << "; R2=" << R2
69 << "; C2=" << C2;
70 std::string ss_str(ss.str());
71 invalid_argument("assign(Eigen::Matrix, Eigen::Matrix)",
72 "", "", ss_str.c_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",
97 "x", x,
98 "y", y);
99 for (int i = 0; i < x.size(); ++i)
100 assign(x(i), y(i));
101 }
102
121 template <typename LHS, typename RHS, int R, int C>
122 inline void
123 assign(Eigen::Block<LHS> x,
124 const Eigen::Matrix<RHS, R, C>& y) {
125 stan::math::check_matching_sizes("assign",
126 "x", x,
127 "y", y);
128 for (int n = 0; n < y.cols(); ++n)
129 for (int m = 0; m < y.rows(); ++m)
130 assign(x(m, n), y(m, n));
131 }
132
133
153 template <typename LHS, typename RHS>
154 inline void
155 assign(std::vector<LHS>& x, const std::vector<RHS>& y) {
156 stan::math::check_matching_sizes("assign",
157 "x", x,
158 "y", y);
159 for (size_t i = 0; i < x.size(); ++i)
160 assign(x[i], y[i]);
161 }
162
163
164 }
165 }
166 #endif
check_matching_dims.hpp
invalid_argument.hpp
check_matching_sizes.hpp
stan::math::check_matching_dims
bool check_matching_dims(const char *function, const char *name1, const Eigen::Matrix< T1, R1, C1 > &y1, const char *name2, const Eigen::Matrix< T2, R2, C2 > &y2)
Return true if the two matrices are of the same size.
Definition: check_matching_dims.hpp:37
stan::math::invalid_argument
void invalid_argument(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw an invalid_argument exception with a consistently formatted message.
Definition: invalid_argument.hpp:31
stan::math::check_matching_sizes
bool check_matching_sizes(const char *function, const char *name1, const T_y1 &y1, const char *name2, const T_y2 &y2)
Return true if two structures at the same size.
Definition: check_matching_sizes.hpp:29
Eigen.hpp
stan::math::assign
void assign(LHS &lhs, const RHS &rhs)
Copy the right-hand side's value to the left-hand side variable.
Definition: assign.hpp:36

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