Commit e3a9ddb2 authored by Davis King's avatar Davis King

Added python_list_to_array()

parent 013dd017
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <dlib/serialize.h> #include <dlib/serialize.h>
#include <array>
namespace py = pybind11; namespace py = pybind11;
...@@ -30,6 +31,24 @@ namespace dlib ...@@ -30,6 +31,24 @@ namespace dlib
return vect; return vect;
} }
template <typename T,size_t N>
std::array<T,N> python_list_to_array (
const py::list& the_list
)
/*!
ensures
- converts a python object into a std::array<T,N> and returns it.
!*/
{
DLIB_CASSERT(len(the_list) == N, "Expected a list of " << N << " things.");
std::array<T,N> vect;
for (unsigned long i = 0; i < vect.size(); ++i)
{
vect[i] = the_list[i].cast<T>();
}
return vect;
}
template <typename T> template <typename T>
py::list vector_to_python_list ( py::list vector_to_python_list (
const std::vector<T>& vect const std::vector<T>& vect
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment