All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
assign.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_FUN_ASSIGN_HPP
#define STAN_MATH_PRIM_MAT_FUN_ASSIGN_HPP
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/scal/err/invalid_argument.hpp>
#include <stan/math/prim/mat/err/check_matching_sizes.hpp>
#include <stan/math/prim/mat/err/check_matching_dims.hpp>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>
namespace stan {
namespace math {
// Recursive assignment with size match checking and promotion
template <typename LHS, typename RHS>
inline void
assign(LHS& lhs, const RHS& rhs) {
lhs = rhs;
}
template <typename LHS, typename RHS, int R1, int C1, int R2, int C2>
inline void
assign(Eigen::Matrix<LHS, R1, C1>& x,
const Eigen::Matrix<RHS, R2, C2>& y) {
std::stringstream ss;
ss << "shapes must match, but found"
<< " R1=" << R1
<< "; C1=" << C1
<< "; R2=" << R2
<< "; C2=" << C2;
std::string ss_str(ss.str());
invalid_argument("assign(Eigen::Matrix, Eigen::Matrix)",
"", "", ss_str.c_str());
}
template <typename LHS, typename RHS, int R, int C>
inline void
assign(Eigen::Matrix<LHS, R, C>& x,
const Eigen::Matrix<RHS, R, C>& y) {
stan::math::check_matching_dims("assign",
"x", x,
"y", y);
for (int i = 0; i < x.size(); ++i)
assign(x(i), y(i));
}
template <typename LHS, typename RHS, int R, int C>
inline void
assign(Eigen::Block<LHS> x,
const Eigen::Matrix<RHS, R, C>& y) {
stan::math::check_matching_sizes("assign",
"x", x,
"y", y);
for (int n = 0; n < y.cols(); ++n)
for (int m = 0; m < y.rows(); ++m)
assign(x(m, n), y(m, n));
}
template <typename LHS, typename RHS>
inline void
assign(std::vector<LHS>& x, const std::vector<RHS>& y) {
stan::math::check_matching_sizes("assign",
"x", x,
"y", y);
for (size_t i = 0; i < x.size(); ++i)
assign(x[i], y[i]);
}
}
}
#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.