13 #include "msdevstudio/MSconfig.h"
29 #ifdef ITERATOR_MEMBER_DEFECT
32 using std::back_insert_iterator;
34 using std::runtime_error;
38 using std::min_element;
39 using std::max_element;
42 using namespace hippodraw;
44 NTuple::NTuple (
const std::string & name )
65 std::size_t
size = labels.size ();
66 for ( std::size_t i = 0; i <
size; i++ ) {
67 vector< double > * vp =
new vector< double > ();
74 m_i_count ( nt.m_i_count ),
75 m_i_current ( nt.m_i_current ),
76 m_i_enabled ( nt.m_i_enabled )
97 vector < string > labels;
98 for (
unsigned int i = 0; i < n; i++ ) {
99 vector<double> * v =
new vector<double> ();
101 labels.push_back (
string (
"nil" ) );
111 m_i_enabled ( false ){
119 m_i_enabled ( false )
127 vector< vector<double> *>::iterator it =
m_data.begin();
128 for ( ; it !=
m_data.end(); ++it ) {
135 size_t old_size =
m_data.size ();
137 if ( new_size > old_size ) {
138 for ( ; old_size < new_size; old_size++ ) {
139 vector< double > * v =
new vector<double> ();
156 const NTuple & ntuple = dynamic_cast <
const NTuple & > ( rhs );
158 vector< vector<double> *>::const_iterator it = ntuple.
m_data.begin();
159 for ( ; it != ntuple.
m_data.end(); ++it ) {
160 vector<double> * v =
new vector<double> ( **it );
170 for (
unsigned int i = 0; i <
columns; i++ ) {
171 vector < double > *
vec =
new vector < double >;
176 for (
unsigned int i = 0; i <
size; i++ ) {
177 const vector < double > & src = rhs.
getRow ( i );
178 for (
unsigned int j = 0; j <
columns; j++ ) {
179 vector < double > & d = *
m_data[j];
180 d.push_back ( src[j] );
193 const NTuple * ntuple = dynamic_cast <
const NTuple * > ( source );
195 vector < vector < double > * >::const_iterator src
196 = ntuple ->
m_data.begin ();
197 vector < vector < double > * >::iterator dst =
m_data.begin();
198 while ( dst !=
m_data.end() ) {
199 vector < double > & dst_vec = *(*dst++);
200 vector < double > & src_vec = *(*src++);
203 back_insert_iterator < vector <double > > ( dst_vec) );
213 vector< vector<double> *>::iterator it =
m_data.begin();
214 for ( ; it <
m_data.end(); ++it ) {
232 unsigned int count = 0;
234 if (
m_data.empty() ==
false &&
244 replaceRow (
unsigned int i,
const std::vector < double > & v )
246 if ( ! ( i <
rows () ) ) {
247 const string what (
"NTuple::replaceRow: index invalid" );
248 throw runtime_error ( what );
253 vector < vector < double > * >:: iterator first =
m_data.begin ();
254 vector < double > :: const_iterator d = v.begin();
255 while ( first !=
m_data.end () ) {
256 vector < double > *
column = *first++;
257 column->operator[] ( i ) = *d++;
266 addRow (
const std::vector < double > & v )
271 for (
unsigned int i = 0; i <
size; i++ ) {
273 column.push_back ( v[i] );
280 insertRow (
unsigned int index,
const std::vector < double > & v )
282 if (
m_data.size() != v.size() ) {
283 const string what (
"NTuple: Attempt to insert a row whose size"
284 " is not equal to other rows." );
286 throw runtime_error ( what );
289 if ( index >
rows () ) {
290 const string what (
"NTuple::insertRow: index out of range" );
292 throw runtime_error ( what );
295 vector<double>::const_iterator vit = v.begin();
296 vector< vector<double> *>::iterator it =
m_data.begin();
297 for ( ; it !=
m_data.end(); ++it ) {
298 vector < double > * p = *it;
299 vector < double > :: iterator where = p->begin() + index;
300 p->insert ( where, *vit++ );
310 if ( index >=
rows () ) {
311 const string what (
"NTuple::insertRow: index out of range" );
312 throw runtime_error ( what );
315 vector< vector<double> *>::iterator it =
m_data.begin();
316 for ( ; it !=
m_data.end(); ++it ) {
317 vector < double > * p = *it;
318 vector < double > :: iterator where = p->begin() + index;
329 if ( row >=
rows () ) {
330 string what (
"NTuple::getRow: argument= ");
332 what +=
" out of range";
333 throw runtime_error ( what );
335 unsigned int cols =
columns ();
338 for (
unsigned int i = 0; i < cols; i++ ) {
340 m_row.push_back ( column[row] );
351 assert ( indices.size() ==
rank );
356 unsigned int row = indices[0] /
size;
357 unsigned int col = indices[0] %
size;
363 unsigned int col = indices[1];
364 unsigned int row = indices[0];
371 unsigned int col = indices[2];
372 unsigned int j = indices[1];
373 unsigned int i = indices[0];
375 assert ( col < size );
379 unsigned int row = j + i *
m_shape[1];
397 vector < vector < double > * >::iterator it =
m_data.begin();
398 for ( ; it !=
m_data.end(); ++it ) {
399 (*it)->reserve ( count );
406 const std::vector< double > & col )
411 string what (
"NTuple: Attempt to add a column with label `");
413 what +=
"' which duplicates existing label.";
414 throw runtime_error ( what );
418 if (
m_data.empty () == false ) {
420 unsigned int rows = col.size();
421 if ( size != 0 && size != rows ) {
422 string what (
"NTuple: Attempt to add a column of `" );
424 what +=
"' rows to DataSource with `";
427 throw runtime_error ( what );
431 vector < double > *
vec =
new vector < double > ( col );
444 string what (
"NTuple: Attempt to replace column `");
446 what +=
"' of data source with only `";
448 what +=
"' columns.";
449 throw runtime_error ( what );
453 unsigned int new_size = data.size ();
454 if ( size != 0 && size != new_size ) {
455 string what (
"NTuple:: Attempt to replace column with size `" );
457 what +=
"' with one of size `";
460 throw runtime_error ( what );
462 m_data[col]->resize ( data.size() );
473 if (
rows () == 0 ) {
477 unsigned int vsize = v.size ();
479 string what (
"NTuple: Attempt to set " );
481 what +=
" labels with data source of ";
484 throw runtime_error ( what );
491 const vector<double> &
504 const string what (
"NTuple::getColumn argument out of range" );
505 throw runtime_error ( what );
523 const vector< double > & c =
getColumn( index );
525 vector < double > :: const_iterator first
526 = min_element ( c.begin(), c.end() );
528 return distance ( c.begin(), first );
537 return *min_element ( v.begin(), v.end() );
544 const vector< double > & c =
getColumn( index );
546 vector < double > :: const_iterator first
547 = max_element ( c.begin(), c.end() );
549 return distance ( c.begin(), first );
558 return *max_element ( v.begin(), v.end() );
563 const vector< double > & c =
getColumn( name );
564 return *min_element( c.begin(), c.end() );
569 const vector< double > & c =
getColumn( name );
570 return *max_element( c.begin(), c.end() );
619 range.
setRange ( v.begin(), v.end() );
631 return accumulate ( data.begin(), data.end(),
sum );