42 unsigned int dim =
m_shape.size();
45 for (
unsigned int i=0; i < dim; i++) {
90 for (
unsigned int i=0; i < n; i++)
108void error (
const std::string& context,
109 const std::string&
msg)
111 throw std::runtime_error (
msg +
": " + context);
127void read_array (Arrayrep& rep,
130 const std::string& context)
136 bool know_size =
false;
137 if (rep.m_shape.size() > nest) {
144 rep.m_shape.push_back (0);
157 if (
rep.m_data.size() > 0 && nest >=
rep.m_shape.size())
158 error (context,
"Bad array nesting");
162 read_array (rep, s, nest+1, context);
164 }
while (
s.at_open());
169 while (
s.at_num (elt)) {
170 rep.m_data.push_back (elt);
177 error (context,
"Missing close bracket");
181 rep.m_shape[nest] =
n;
183 else if (
rep.m_shape[nest] != n) {
186 error (context,
"Array not rectangular");
207 else if (
str ==
"False")
211 std::istringstream is (
str);
217 read_array (*
this, s, 0, context);
222 error (context,
"Number expected");
228 error (context,
"End of vector before end of string");
247 stream <<
"[ ]" << std::endl;
252 stream <<
m_data[0] << std::endl;
259 for (
unsigned i=1;i<
m_shape.size();i++)
261 if (totSize!=
m_data.size())
262 error(
"",
"Array is inconsistent!");
264 std::vector<Arrayelt>::size_type dataIndex=0;
266 stream <<
"]" << std::endl;
280 if (dimIndex<(
m_shape.size()-1)) {
282 for (
unsigned i=0;i<
m_shape[dimIndex];i++) {
291 stream <<
"[" <<
m_data[idx++];
292 for (
unsigned i=1;i<
m_shape[dimIndex];i++)
293 stream <<
", " <<
m_data[idx++];
Helper class for converting strings to Array's.
Representation class for Array's.
Helper class for converting strings to Array's.
Namespace for helper functions.
float Arrayelt
The type of an element of an Array.
void write_array(std::ostream &stream) const
Creates a text representation of the array content.
void write_subarray(std::ostream &stream, std::vector< Arrayelt >::size_type &idx, unsigned dimIndex) const
Helper function for write_array.
std::vector< Arrayelt > m_data
The array data, stored using the C array ordering.
void init_sizes(bool resize_data=false)
Initialize the m_sizes vector from the m_shape vector.
Arrayrep()
Default constructor.
std::vector< unsigned int > m_sizes
Subarray sizes, for faster access.
std::vector< unsigned int > m_shape
The array shape.