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 > &