1 #ifndef STAN_IO_VAR_CONTEXT_HPP
2 #define STAN_IO_VAR_CONTEXT_HPP
42 virtual bool contains_r(
const std::string& name)
const = 0;
56 virtual std::vector<double>
vals_r(
const std::string& name)
const = 0;
66 virtual std::vector<size_t>
dims_r(
const std::string& name)
const = 0;
76 virtual bool contains_i(
const std::string& name)
const = 0;
86 virtual std::vector<int>
vals_i(
const std::string& name)
const = 0;
96 virtual std::vector<size_t>
dims_i(
const std::string& name)
const = 0;
104 virtual void names_r(std::vector<std::string>& names)
const = 0;
112 virtual void names_i(std::vector<std::string>& names)
const = 0;
115 const std::vector<size_t>& dims)
const {
117 for (
size_t i = 0; i < dims.size(); ++i) {
118 if (i > 0) msg <<
',';
125 const std::string& name,
126 const std::string& base_type,
127 const std::vector<size_t>& dims_declared)
const {
128 bool is_int_type = base_type ==
"int";
131 std::stringstream msg;
133 ?
"int variable contained non-int values"
134 :
"variable does not exist" )
135 <<
"; processing stage=" << stage
136 <<
"; variable name=" << name
137 <<
"; base type=" << base_type;
138 throw std::runtime_error(msg.str());
142 std::stringstream msg;
143 msg <<
"variable does not exist"
144 <<
"; processing stage=" << stage
145 <<
"; variable name=" << name
146 <<
"; base type=" << base_type;
147 throw std::runtime_error(msg.str());
150 std::vector<size_t> dims =
dims_r(name);
151 if (dims.size() != dims_declared.size()) {
152 std::stringstream msg;
153 msg <<
"mismatch in number dimensions declared and found in context"
154 <<
"; processing stage=" << stage
155 <<
"; variable name=" << name
156 <<
"; dims declared=";
158 msg <<
"; dims found=";
160 throw std::runtime_error(msg.str());
162 for (
size_t i = 0; i < dims.size(); ++i) {
163 if (dims_declared[i] != dims[i]) {
164 std::stringstream msg;
165 msg <<
"mismatch in dimension declared and found in context"
166 <<
"; processing stage=" << stage
167 <<
"; variable name=" << name
170 <<
"; dims declared=";
172 msg <<
"; dims found=";
174 throw std::runtime_error(msg.str());
180 return std::vector<size_t>();
182 static std::vector<size_t>
to_vec(
size_t n1) {
183 std::vector<size_t> v(1);
187 static std::vector<size_t>
to_vec(
size_t n1,
size_t n2) {
188 std::vector<size_t> v(2);
193 static std::vector<size_t>
to_vec(
size_t n1,
size_t n2,
195 std::vector<size_t> v(3);
201 static std::vector<size_t>
to_vec(
size_t n1,
size_t n2,
202 size_t n3,
size_t n4) {
203 std::vector<size_t> v(4);
210 static std::vector<size_t>
to_vec(
size_t n1,
size_t n2,
211 size_t n3,
size_t n4,
213 std::vector<size_t> v(5);
221 static std::vector<size_t>
to_vec(
size_t n1,
size_t n2,
222 size_t n3,
size_t n4,
223 size_t n5,
size_t n6) {
224 std::vector<size_t> v(6);
233 static std::vector<size_t>
to_vec(
size_t n1,
size_t n2,
234 size_t n3,
size_t n4,
235 size_t n5,
size_t n6,
237 std::vector<size_t> v(7);
247 static std::vector<size_t>
to_vec(
size_t n1,
size_t n2,
248 size_t n3,
size_t n4,
249 size_t n5,
size_t n6,
250 size_t n7,
size_t n8) {
251 std::vector<size_t> v(8);
static std::vector< size_t > to_vec(size_t n1, size_t n2, size_t n3, size_t n4)
Probability, optimization and sampling library.
static std::vector< size_t > to_vec(size_t n1, size_t n2, size_t n3, size_t n4, size_t n5, size_t n6)
virtual std::vector< int > vals_i(const std::string &name) const =0
Return the integer values for the variable of the specified name in last-index-major order or the emp...
static std::vector< size_t > to_vec()
virtual std::vector< double > vals_r(const std::string &name) const =0
Return the floating point values for the variable of the specified variable name in last-index-major ...
void validate_dims(const std::string &stage, const std::string &name, const std::string &base_type, const std::vector< size_t > &dims_declared) const
virtual bool contains_r(const std::string &name) const =0
Return true if the specified variable name is defined.
virtual bool contains_i(const std::string &name) const =0
Return true if the specified variable name has integer values.
static std::vector< size_t > to_vec(size_t n1)
virtual void names_i(std::vector< std::string > &names) const =0
Return a list of the names of the integer variables in the context.
static std::vector< size_t > to_vec(size_t n1, size_t n2, size_t n3, size_t n4, size_t n5, size_t n6, size_t n7)
virtual void names_r(std::vector< std::string > &names) const =0
Return a list of the names of the floating point variables in the context.
A var_reader reads array variables of integer and floating point type by name and dimension...
static std::vector< size_t > to_vec(size_t n1, size_t n2, size_t n3)
void add_vec(std::stringstream &msg, const std::vector< size_t > &dims) const
virtual std::vector< size_t > dims_r(const std::string &name) const =0
Return the dimensions for the specified floating point variable.
virtual std::vector< size_t > dims_i(const std::string &name) const =0
Return the dimensions of the specified floating point variable.
static std::vector< size_t > to_vec(size_t n1, size_t n2)
static std::vector< size_t > to_vec(size_t n1, size_t n2, size_t n3, size_t n4, size_t n5, size_t n6, size_t n7, size_t n8)
static std::vector< size_t > to_vec(size_t n1, size_t n2, size_t n3, size_t n4, size_t n5)