13 #define PY_ARRAY_UNIQUE_SYMBOL HippoPyArrayHandle
14 #define NO_IMPORT_ARRAY
22 #define NO_IMPORT_ARRAY
24 #include <boost/python.hpp>
26 #include <numpy/noprefix.h>
29 #include <Numeric/arrayobject.h>
31 #include <numarray/arrayobject.h>
52 boost::python::numeric::array
makeNum(boost::python::object x);
61 boost::python::numeric::array
makeNum(
intp n, PyArray_TYPES t);
70 boost::python::numeric::array
makeNum(std::vector<int> dimens,
82 template <
typename T> PyArray_TYPES
getEnum ();
84 template<
typename T> PyArray_TYPES
getEnum(
void)
86 PyErr_SetString(PyExc_ValueError,
"no mapping available for this type");
87 boost::python::throw_error_already_set();
92 template <
typename T> PyArray_TYPES
getEnum ();
103 template <
typename T> boost::python::numeric::array
makeNum(
T*
data,
int n = 0){
104 boost::python::object obj(boost::python::handle<>(PyArray_FromDims(1, &n, getEnum<T>())));
106 void *arr_data = PyArray_DATA((PyArrayObject*) obj.ptr());
107 memcpy(arr_data, data, PyArray_ITEMSIZE((PyArrayObject*) obj.ptr()) * n);
109 char *arr_data = ((PyArrayObject*) obj.ptr())->data;
110 memcpy(arr_data, data,
sizeof(
T) * n);
114 return boost::python::extract<boost::python::numeric::array>(obj);
127 template <
typename T> boost::python::numeric::array
makeNum(
T *
data, std::vector<int> dims){
128 intp total = std::accumulate(dims.begin(),dims.end(),1,std::multiplies<intp>());
129 boost::python::object obj(boost::python::handle<>(PyArray_FromDims(dims.size(),&dims[0], getEnum<T>())));
131 void *arr_data = PyArray_DATA((PyArrayObject*) obj.ptr());
132 memcpy(arr_data, data, PyArray_ITEMSIZE((PyArrayObject*) obj.ptr()) * total);
134 char *arr_data = ((PyArrayObject*) obj.ptr())->data;
135 memcpy(arr_data, data,
sizeof(
T) * total);
139 return boost::python::extract<boost::python::numeric::array>(obj);
143 std::vector < int> dims );
150 boost::python::numeric::array
makeNum(
const
151 boost::python::numeric::array& arr);
158 PyArray_TYPES
type(boost::python::numeric::array arr);
167 void check_type(boost::python::numeric::array arr,
168 PyArray_TYPES expected_type);
175 int rank(boost::python::numeric::array arr);
183 void check_rank(boost::python::numeric::array arr,
int expected_rank);
190 intp size(boost::python::numeric::array arr);
199 void check_size(boost::python::numeric::array arr,
intp expected_size);
206 std::vector<intptr_t>
shape(boost::python::numeric::array arr);
214 intp get_dim(boost::python::numeric::array arr,
int dimnum);
223 void check_shape(boost::python::numeric::array arr,
224 std::vector<intp> expected_dims);
234 void check_dim(boost::python::numeric::array arr,
int dimnum,
intp dimsize);
255 void*
data(boost::python::numeric::array arr);
263 void copy_data(boost::python::numeric::array arr,
char* new_data);
270 boost::python::numeric::array
clone(boost::python::numeric::array arr);
278 boost::python::numeric::array
astype(boost::python::numeric::array arr,
286 int refcount(boost::python::numeric::array arr);
293 std::vector<intp>
strides(boost::python::numeric::array arr);