13 #include <boost/python.hpp>
26 using namespace boost::python;
28 using std::runtime_error;
65 using namespace hippodraw;
67 ListTuple::ListTuple ()
82 PyGILState_STATE gstate;
83 gstate = PyGILState_Ensure ();
87 object obj = sequence.attr (
"__len__" ) ();
88 unsigned int size = extract < unsigned int > ( obj );
92 PyGILState_Release ( gstate );
117 unsigned int size = 0;
118 if (
m_data.empty () == false ) {
138 assert ( column <
m_data.size () );
145 assert ( row < size );
147 object result = seq[row];
148 value = extract < double > ( result );
156 const std::vector < double > &
161 m_row.resize ( size );
175 for (
unsigned int i = 0;
i <
size;
i++ ) {
176 object obj = array[
i];
177 extract < double > check ( obj );
178 if ( check.check() == false ) {
196 string what (
"ListTuple Attempt to add a column whose label"
197 " is same as other column." );
198 throw runtime_error ( what );
201 unsigned int new_size =
getSize ( array );
203 if (
m_data.empty () == false ) {
204 unsigned int old_size =
rows ();
206 if ( old_size != 0 && old_size != new_size ) {
207 string what (
"ListTuple Attempt to add a column whose size"
208 " is not equal to other columns." );
209 throw runtime_error ( what );
213 string what (
"ListTuple: Attempt to add a column with one or more"
214 " elements not convertable to float" );
215 throw runtime_error ( what );
218 m_data.push_back ( array );
231 const string what (
"NunArrayTuple: column doesn't exist" );
232 throw runtime_error ( what );
236 int old_size =
getSize ( old_array );
237 int new_size =
getSize ( array );
239 if ( old_size != 0 && old_size != new_size ) {
240 const string what (
"ListTuple: Attempt to replace column with one "
241 "whose size is not equal to other columns." );
242 throw runtime_error ( what );
266 const vector < unsigned int > &
virtual void notifyObservers() const
Notifies Observer objects of a change.
virtual void clear()
Raises assertion because the contained Python list should not be changed.
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)
Raises assertion because the contained Python list should not be changed.
const std::vector< unsigned int > & getShape() const
Returns the shape of the data elements.
std::vector< intptr_t > shape(numeric::array arr)
virtual double operator[](std::vector< unsigned int > &indices) const
Raises assertion because this method is not implemented yet.
virtual void notifyObservers() const
Notifies observers.
std::vector< unsigned int > m_shape
The shape of the data.
virtual void setShape(std::vector< unsigned int > &shape)
Sets the shape of the data elements.
hippodraw::ListTuple class interface.
intp size(numeric::array arr)
bool isAcceptable(const boost::python::list &seq)
Returns true if all the elements of the list seq can be converted to type double, otherwise returns f...
void replaceColumn(unsigned int index, boost::python::list array)
Replaces the column indexed by index with the array.
virtual void copy(const DataSource &)
Raises an exception as with this release copying is not supported.
std::vector< boost::python::list > m_data
The numarray objects that contains the data.
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.
int addColumn(const std::string &label, boost::python::list seq)
Adds a column to the end of the ListTuple.
virtual unsigned int rows() const
Returns the size of the slice for the next to last dimension.
hippodraw::Range class interface
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.
unsigned static int getSize(const boost::python::list &sequence)
std::vector< double > m_row
A temporary array of data from one row of each column.
virtual bool empty() const
Returns true, if ListTuple is empty, i.e.
A wrapper class for Python list objects.
virtual ~ListTuple()
The destructor.
Base class for DataSource.
virtual const std::vector< double > & getRow(unsigned int index) const
Returns a const reference to slice along the axis known as a row.