Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
e3a9ddb2
Commit
e3a9ddb2
authored
May 24, 2018
by
Davis King
Browse files
Added python_list_to_array()
parent
013dd017
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
0 deletions
+19
-0
dlib/python/pybind_utils.h
dlib/python/pybind_utils.h
+19
-0
No files found.
dlib/python/pybind_utils.h
View file @
e3a9ddb2
...
...
@@ -7,6 +7,7 @@
#include <vector>
#include <string>
#include <dlib/serialize.h>
#include <array>
namespace
py
=
pybind11
;
...
...
@@ -30,6 +31,24 @@ namespace dlib
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
>
py
::
list
vector_to_python_list
(
const
std
::
vector
<
T
>&
vect
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment