13 #include <boost/python.hpp>
20 #define PY_ARRAY_UNIQUE_SYMBOL HippoPyArrayHandle
21 #define NO_IMPORT_ARRAY
32 using namespace boost::python;
34 using std::runtime_error;
38 using namespace hippodraw;
40 NumArrayTuple::NumArrayTuple ()
67 unsigned int size = 0;
69 if (
m_data.empty () == false ) {
91 #if HAVE_NUMPY || HAVE_NUMERIC
92 PyGILState_STATE state = PyGILState_Ensure ();
95 assert ( column <
m_data.size () );
100 assert ( row < static_cast < unsigned int > ( size ) );
102 object result = array[row];
104 double value = extract < double > ( result );
105 #if HAVE_NUMPY || HAVE_NUMERIC
106 PyGILState_Release ( state );
115 const std::vector < double > &
120 m_row.resize ( size );
133 boost::python::numeric::array array )
138 string what (
"NumArrayTuple Attempt to add a column whose label, `");
140 what +=
"', is same as existing column.";
141 throw runtime_error ( what );
146 if (
m_data.empty () == false ) {
147 unsigned int old_size =
rows ();
149 if ( old_size != 0 && old_size != new_size ) {
150 string what (
"NumArrayTuple Attempt to add a column whose size"
151 " is not equal to other columns." );
152 throw runtime_error ( what );
155 m_data.push_back ( array );
164 boost::python::numeric::array array )
168 const string what (
"NunArrayTuple: column doesn't exist" );
169 throw runtime_error ( what );
172 const numeric::array old_array =
m_data[col];
176 if ( old_size != 0 && old_size != new_size ) {
177 const string what (
"NumArrayTuple: Attempt to replace column with one "
178 "whose size is not equal to other columns." );
179 throw runtime_error ( what );
189 boost::python::numeric::array array )
191 unsigned int index =
indexOf ( column );
201 if ( index >= size ) {
202 const string what (
"NunArrayTuple: column doesn't exist" );
203 throw runtime_error ( what );
212 unsigned int index =
indexOf ( label );
223 const vector < unsigned int > &
virtual bool empty() const
Returns true, if NumArrayTuple is empty, i.e.
hippodraw::Range class interface
virtual void setShape(std::vector< unsigned int > &shape)
Sets the shape of the data elements.
void replaceColumn(unsigned int index, boost::python::numeric::array array)
Replaces the column indexed by index with the array.
boost::python::numeric::array getNumArray(const std::string &label) const
Return the reference to the desired numarray by column label.
virtual void reserve(unsigned int count)
Raises assertion as this method is not implemented yet.
std::vector< unsigned int > m_shape
The shape of the data.
Base class for DataSource.
virtual void notifyObservers() const
Notifies Observer objects of a change.
virtual ~NumArrayTuple()
The destructor.
std::vector< intptr_t > shape(numeric::array arr)
intp get_dim(boost::python::numeric::array arr, int dimnum)
Returns the size of a specific dimension.
virtual void fillShape(std::vector< intptr_t > &v, unsigned int column) const
Fills the vector with the shape of a column.
virtual double valueAt(unsigned int row, unsigned int column) const
unsigned int columns() const
Returns the number of columns or data arrays available from this DataSource.
std::vector< boost::python::numeric::array > m_data
The numarray objects that contains the data.
virtual void copy(const DataSource &)
Raises exception because with this release making a copy is not supported.
hippodraw::NumArrayTuple class interface.
virtual int indexOf(const std::string &label) const
Returns true if the specified column labeled label has been filled.
intp size(numeric::array arr)
column
The column indices for 2 dimension data point tuple.
virtual unsigned int rows() const
Returns the size of the slice for the next to last dimension.
virtual const std::vector< double > & getRow(unsigned int index) const
Returns a const reference to slice along the axis known as a row.
virtual void clear()
Raises assertion as this method is not implemented yet.
std::vector< double > m_row
A temporary array of data from one row of each column.
virtual void addLabel(const std::string &label)
Adds a new label for a column.
int addColumn(const std::string &label, boost::python::numeric::array array)
Adds a column to the end of the NumArrayTuple.
virtual void notifyObservers() const
Notifies observers.
virtual double operator[](std::vector< unsigned int > &indices) const
Raises assertion as this method is not implemented yet.
const std::vector< unsigned int > & getShape() const
Returns the shape of the data elements.