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