13 #include <boost/python.hpp>
20 #define PY_ARRAY_UNIQUE_SYMBOL HippoPyArrayHandle
21 #define NO_IMPORT_ARRAY
34 using std::runtime_error;
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 > &
column
The column indices for 2 dimension data point tuple.
const std::vector< unsigned int > & getShape() const
Returns the shape of the data elements.
virtual void setShape(std::vector< unsigned int > &shape)
Sets the shape of the data elements.
virtual bool empty() const
Returns true, if NumArrayTuple is empty, i.e.
std::vector< boost::python::numeric::array > m_data
The numarray objects that contains the data.
void replaceColumn(unsigned int index, boost::python::numeric::array array)
Replaces the column indexed by index with the array.
virtual void copy(const DataSource &)
Raises exception because with this release making a copy is not supported.
std::vector< double > m_row
A temporary array of data from one row of each column.
virtual ~NumArrayTuple()
The destructor.
hippodraw::NumArrayTuple class interface.
virtual void notifyObservers() const
Notifies Observer objects of a change.
hippodraw::Range class interface
intp size(numeric::array arr)
virtual double valueAt(unsigned int row, unsigned int column) const
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.
boost::python::numeric::array getNumArray(const std::string &label) const
Return the reference to the desired numarray by column label.
virtual void fillShape(std::vector< intptr_t > &v, unsigned int column) const
Fills the vector with the shape of a column.
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 void clear()
Raises assertion as this method is not implemented yet.
virtual double operator[](std::vector< unsigned int > &indices) const
Raises assertion as this method is not implemented yet.
virtual unsigned int rows() const
Returns the size of the slice for the next to last dimension.
std::vector< unsigned int > m_shape
The shape of the data.
int addColumn(const std::string &label, boost::python::numeric::array array)
Adds a column to the end of the NumArrayTuple.
virtual void reserve(unsigned int count)
Raises assertion as this method is not implemented yet.
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 notifyObservers() const
Notifies observers.
virtual void addLabel(const std::string &label)
Adds a new label for a column.