All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PyUtils.h
Go to the documentation of this file.
1 #ifndef __OPT0FINDER_PYUTILS_H__
2 #define __OPT0FINDER_PYUTILS_H__
3 
4 struct _object;
5 typedef _object PyObject;
6 
7 #include <Python.h>
8 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
9 //#include <numpy/ndarrayobject.h>
10 #include "numpy/arrayobject.h"
11 #include <vector>
14 namespace flashmatch {
15  /// Utility function: call one-time-only numpy module initialization (you don't have to call)
16  void SetPyUtil();
17 
18  PyObject* as_ndarray(const QCluster_t& traj);
19  PyObject* as_ndarray(const Flash_t& traj);
20  PyObject* as_ndarray(const ::geoalgo::Trajectory& traj);
21 
22  /// convert vectors into np array
23  template <class T>
24  PyObject* _as_ndarray(const std::vector<T>& data);
25  PyObject* as_ndarray(const std::vector< short > &data);
26  PyObject* as_ndarray(const std::vector< unsigned short > &data);
27  PyObject* as_ndarray(const std::vector< int > &data);
28  PyObject* as_ndarray(const std::vector< unsigned int > &data);
29  PyObject* as_ndarray(const std::vector< long long > &data);
30  PyObject* as_ndarray(const std::vector< unsigned long long > &data);
31  PyObject* as_ndarray(const std::vector< float > &data);
32  PyObject* as_ndarray(const std::vector< double > &data);
33 
34  /// copy array
35  template <class T>
36  void _copy_array(PyObject *arrayin, const std::vector<T> &cvec);
37  void copy_array(PyObject *arrayin, const std::vector< unsigned short > &cvec);
38  void copy_array(PyObject *arrayin, const std::vector< unsigned int > &cvec);
39  void copy_array(PyObject *arrayin, const std::vector< short > &cvec);
40  void copy_array(PyObject *arrayin, const std::vector< int > &cvec);
41  void copy_array(PyObject *arrayin, const std::vector< long long > &cvec);
42  void copy_array(PyObject *arrayin, const std::vector< float > &cvec);
43  void copy_array(PyObject *arrayin, const std::vector< double > &cvec);
44 
45  template <class T> int ctype_to_numpy();
46  template<> int ctype_to_numpy<short>();
47  template<> int ctype_to_numpy<unsigned short>();
48  template<> int ctype_to_numpy<int>();
49  template<> int ctype_to_numpy<unsigned int>();
50  template<> int ctype_to_numpy<long long>();
51  template<> int ctype_to_numpy<unsigned long long>();
52  template<> int ctype_to_numpy<float>();
53  template<> int ctype_to_numpy<double>();
54  template <class T> PyObject* numpy_array(std::vector<size_t> dims);
55 }
56 
57 #endif
void SetPyUtil()
Utility function: call one-time-only numpy module initialization (you don&#39;t have to call) ...
Definition: PyUtils.cxx:14
_object PyObject
Definition: PyUtils.h:4
PyObject * _as_ndarray(const std::vector< T > &vec)
convert vectors into np array
Definition: PyUtils.cxx:193
int ctype_to_numpy< short >()
Definition: PyUtils.cxx:164
int ctype_to_numpy< float >()
Definition: PyUtils.cxx:170
void copy_array(PyObject *arrayin, const std::vector< unsigned short > &cvec)
Definition: PyUtils.cxx:156
int ctype_to_numpy< unsigned long long >()
Definition: PyUtils.cxx:169
PyObject * as_ndarray(const QCluster_t &traj)
Definition: PyUtils.cxx:22
int ctype_to_numpy< unsigned int >()
Definition: PyUtils.cxx:167
int ctype_to_numpy< long long >()
Definition: PyUtils.cxx:168
int ctype_to_numpy< double >()
Definition: PyUtils.cxx:171
void _copy_array(PyObject *arrayin, const std::vector< T > &cvec)
copy array
Definition: PyUtils.cxx:124
PyObject * numpy_array(std::vector< size_t > dims)
Definition: PyUtils.cxx:227
int ctype_to_numpy< unsigned short >()
Definition: PyUtils.cxx:165
int ctype_to_numpy()
int ctype_to_numpy< int >()
Definition: PyUtils.cxx:166