| 1 |
#ifndef __TYPES_H__ |
| 2 |
#define __TYPES_H__ |
| 3 |
|
| 4 |
#include <pybind11/pybind11.h> |
| 5 |
#include <pybind11/numpy.h> |
| 6 |
|
| 7 |
#include <vector> |
| 8 |
#include <iostream> |
| 9 |
|
| 10 |
|
| 11 |
namespace pyopengv { |
| 12 |
|
| 13 |
namespace py = pybind11; |
| 14 |
|
| 15 |
typedef py::array_t<double, py::array::c_style | py::array::forcecast> pyarray_d; |
| 16 |
|
| 17 |
template <typename T> |
| 18 |
py::array_t<T> py_array_from_data(const T *data, size_t shape0) { |
| 19 |
py::array_t<T> res({shape0}); |
| 20 |
std::copy(data, data + shape0, res.mutable_data()); |
| 21 |
return res; |
| 22 |
} |
| 23 |
|
| 24 |
template <typename T> |
| 25 |
py::array_t<T> py_array_from_data(const T *data, size_t shape0, size_t shape1) { |
| 26 |
py::array_t<T> res({shape0, shape1}); |
| 27 |
std::copy(data, data + shape0 * shape1, res.mutable_data()); |
| 28 |
return res; |
| 29 |
} |
| 30 |
|
| 31 |
template <typename T> |
| 32 |
py::array_t<T> py_array_from_vector(const std::vector<T> &v) { |
| 33 |
const T *data = v.size() ? &v[0] : NULL; |
| 34 |
return py_array_from_data(data, v.size()); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
} |
| 39 |
|
| 40 |
#endif // __TYPES_H__ |