13 #include <boost/python.hpp> 28 using std::runtime_error;
67 ListTuple::ListTuple ()
78 getSize (
const boost::python::list & sequence )
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 ) {
119 const boost::python::list & seq =
m_data[0];
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 ) {
191 boost::python::list array )
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 );
227 boost::python::list array )
231 const string what (
"NunArrayTuple: column doesn't exist" );
232 throw runtime_error ( what );
235 const boost::python::list & old_array =
m_data[col];
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 );
252 boost::python::list array )
254 unsigned int index =
indexOf ( column );
266 const vector < unsigned int > &
const std::vector< unsigned int > & getShape() const
Returns the shape of the data elements.
std::vector< unsigned int > m_shape
The shape of the data.
std::vector< double > m_row
A temporary array of data from one row of each column.
virtual void notifyObservers() const
Notifies observers.
virtual bool empty() const
Returns true, if ListTuple is empty, i.e.
virtual int indexOf(const std::string &label) const
Returns true if the specified column labeled label has been filled.
void replaceColumn(unsigned int index, boost::python::list array)
Replaces the column indexed by index with the array.
unsigned int columns() const
Returns the number of columns or data arrays available from this DataSource.
virtual void notifyObservers() const
Notifies Observer objects of a change.
hippodraw::ListTuple class interface.
virtual const std::vector< double > & getRow(unsigned int index) const
Returns a const reference to slice along the axis known as a row.
int addColumn(const std::string &label, boost::python::list seq)
Adds a column to the end of the ListTuple.
virtual void clear()
Raises assertion because the contained Python list should not be changed.
Base class for DataSource.
virtual void addLabel(const std::string &label)
Adds a new label for a column.
virtual void reserve(unsigned int count)
Raises assertion because the contained Python list should not be changed.
intp size(numeric::array arr)
std::vector< boost::python::list > m_data
The numarray objects that contains the data.
virtual ~ListTuple()
The destructor.
virtual void copy(const DataSource &)
Raises an exception as with this release copying is not supported.
unsigned static int getSize(const boost::python::list &sequence)
virtual unsigned int rows() const
Returns the size of the slice for the next to last dimension.
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...
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.
virtual void setShape(std::vector< unsigned int > &shape)
Sets the shape of the data elements.
column
The column indices for 2 dimension data point tuple.
hippodraw::Range class interface
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.