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++);
201 std::copy ( src_vec.begin(),
203 back_insert_iterator < vector <double > > ( dst_vec) );
213 vector< vector<double> *>::iterator
it =
m_data.begin();
232 unsigned int count = 0;
234 if (
m_data.empty() ==
false &&
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++;
271 for (
unsigned int i = 0;
i <
size;
i++ ) {
273 column.push_back ( v[
i] );
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() );
464 std:: copy ( data.begin (), data.end(),
m_data[col]->begin() );
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 );
virtual double sum(unsigned int column) const
Returns the sum of all the elements in the sequence of column column.
virtual void copy(const DataSource &rhs)
Copies rhs data.
void replaceRow(unsigned int i, const std::vector< double > &data)
Replaces the data in the row i.
virtual void notifyObservers() const
Notifies Observer objects of a change.
virtual bool fillRange(unsigned int column, Range &) const
Returns the Range of data in the column via the argument.
virtual void eraseRow(unsigned int index)
Erases a row from the NTuple.
void throwIfInvalidRowSize(const std::vector< double > &row)
Throws a DataSourceException if the size of the row is not equal to the number of columns...
virtual const std::vector< double > & getColumn(unsigned int index) const
Returns the data in the column with index column.
virtual void clear()
Clears the NTuple.
virtual void replaceColumn(unsigned int index, const std::vector< double > &data)
Replaces the data in column col.
void * data(numeric::array arr)
virtual void addLabel(const std::string &label)
Adds a new label for a column.
column
The column indices for 2 dimension data point tuple.
virtual void reserve(unsigned int count)
For each column, reserves enough space for the data source to grow to count rows. ...
virtual void willDelete(const Observable *)
Notifies this Observer object that one of its Observable objects is about to be deleted.
virtual double valueAt(unsigned int row, unsigned int column) const
Returns the value in the table in position given by the row and column indexes.
void setLabels(const std::vector< std::string > &v)
Assigns the label to each column from the vector of strings.
virtual unsigned int rows() const
Returns the number of rows.
virtual void addRow(const std::vector< double > &v)
Adds a row to the end of the ntuple.
int m_i_count
The interval count.
The namespace for conversion to string.
bool isIntervalEnabled() const
Returns true if interval counting is enabled, otherwise returns false.
std::vector< unsigned int > m_shape
The shape of the data.
hippodraw::NTuple class interface.
unsigned int getRank() const
Returns the rank of the data source.
std::vector< std::vector< double > * > m_data
The data columns of the data source table.
virtual void append(const DataSource *source)
Appends the data from the source.
virtual void insertRow(unsigned int index, const std::vector< double > &v)
Inserts a Row.
virtual void copyPrivate(const DataSource &other)
Copies the contents of the other DataSource.
virtual double minElement(unsigned int index) const
Returns the value of the minimum element of column index.
virtual void append(const DataSource *source)
Appends the contents of the DataSource source.
bool isValidColumn(unsigned int index) const
Returns true if index is valid, otherwise throws a DataSourceException.
unsigned int getIntervalCount() const
Returns the current interval count.
intp size(numeric::array arr)
int m_i_current
The current interval count.
int rank(numeric::array arr)
string convert(int i)
Converts an integer to a string.
double columnMax(const std::string &name) const
Returns minimum element in a column whose label is given by name.
virtual int addColumn(const std::string &, const std::vector< double > &column)
Adds a column to the end of the ntuple and returns the index to the added column. ...
virtual unsigned int indexOfMaxElement(unsigned int index) const
Returns row index of the maximum element in a column for the given column.
void setRange(double low, double high, double pos)
Changes the current Range.
virtual void throwIfInvalidLabel(const std::string &label) const
Throws a DataSourceException object if label is not a valid label for this DataSource.
A DataSource class implemented with std::vector<double> to store the column data. ...
virtual void notifyObservers() const
Notifies Observer objects of a change.
bool m_i_enabled
The interval flag.
virtual ~NTuple()
The destructor.
virtual unsigned int rows() const =0
Returns the number of rows.
virtual void checkWidth(const DataSource *source)
Checks the number of columns.
virtual bool empty() const
Returns true, if NTuple is empty, i.e.
hippodraw::Range class interface
virtual const std::vector< double > & getRow(unsigned int index) const
Returns a temporary vector of data elements in one row.
virtual int indexOf(const std::string &label) const
Returns true if the specified column labeled label has been filled.
unsigned int columns() const
Returns the number of columns or data arrays available from this DataSource.
virtual unsigned int indexOfMinElement(unsigned int index) const
Returns row index of the minimum element in a column for the given column.
void resizeColumns(size_t new_size)
Resizes the the number of columns of the NTuple.
virtual double maxElement(unsigned int index) const
Returns the value of the maximum element of column index.
Expresses a range of values.
double columnMin(const std::string &name) const
Returns minimum element in a column whose label is given by name.
void setIntervalCount(int number)
Sets the interval count.
NTuple()
The default constructor creating an ntuple with 0 columns.
std::vector< double > m_row
A temporary vector corresponding to data elements of one row.
virtual void setLabels(const std::vector< std::string > &v)
Assigns the label to each column from the vector of strings @ v.
virtual const std::vector< double > & getRow(unsigned int) const =0
Returns a const reference to slice along the axis known as a row.
list< QAction * >::iterator it
virtual double operator[](std::vector< unsigned int > &indices) const
Observer class interface.
Base class for DataSource.
void setIntervalEnabled(bool yes=true)
Sets interval counting to be enabled.