Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
6980697a
Commit
6980697a
authored
Apr 28, 2018
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Just moved code into dlib namespace.
parent
43e5f42e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
33 deletions
+44
-33
pybind_utils.h
dlib/python/pybind_utils.h
+31
-27
serialize_pickle.h
dlib/python/serialize_pickle.h
+13
-6
No files found.
dlib/python/pybind_utils.h
View file @
6980697a
...
...
@@ -10,69 +10,73 @@
namespace
py
=
pybind11
;
template
<
typename
T
>
std
::
vector
<
T
>
python_list_to_vector
(
namespace
dlib
{
template
<
typename
T
>
std
::
vector
<
T
>
python_list_to_vector
(
const
py
::
list
&
obj
)
/*!
)
/*!
ensures
- converts a python object into a std::vector<T> and returns it.
!*/
{
!*/
{
std
::
vector
<
T
>
vect
(
len
(
obj
));
for
(
unsigned
long
i
=
0
;
i
<
vect
.
size
();
++
i
)
{
vect
[
i
]
=
obj
[
i
].
cast
<
T
>
();
}
return
vect
;
}
}
template
<
typename
T
>
py
::
list
vector_to_python_list
(
template
<
typename
T
>
py
::
list
vector_to_python_list
(
const
std
::
vector
<
T
>&
vect
)
/*!
)
/*!
ensures
- converts a std::vector<T> into a python list object.
!*/
{
!*/
{
py
::
list
obj
;
for
(
unsigned
long
i
=
0
;
i
<
vect
.
size
();
++
i
)
obj
.
append
(
vect
[
i
]);
return
obj
;
}
}
template
<
typename
T
>
void
extend_vector_with_python_list
(
template
<
typename
T
>
void
extend_vector_with_python_list
(
std
::
vector
<
T
>
&
v
,
const
py
::
list
&
l
)
/*!
)
/*!
ensures
- appends items from a python list to the end of std::vector<T>.
!*/
{
!*/
{
for
(
const
auto
&
item
:
l
)
v
.
push_back
(
item
.
cast
<
T
>
());
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
std
::
shared_ptr
<
T
>
load_object_from_file
(
template
<
typename
T
>
std
::
shared_ptr
<
T
>
load_object_from_file
(
const
std
::
string
&
filename
)
/*!
)
/*!
ensures
- deserializes an object of type T from the given file and returns it.
!*/
{
!*/
{
std
::
ifstream
fin
(
filename
.
c_str
(),
std
::
ios
::
binary
);
if
(
!
fin
)
throw
dlib
::
error
(
"Unable to open "
+
filename
);
auto
obj
=
std
::
make_shared
<
T
>
();
deserialize
(
*
obj
,
fin
);
return
obj
;
}
}
// ----------------------------------------------------------------------------------------
...
...
dlib/python/serialize_pickle.h
View file @
6980697a
...
...
@@ -8,9 +8,14 @@
#include <sstream>
#include <dlib/vectorstream.h>
template
<
typename
T
>
py
::
tuple
getstate
(
const
T
&
item
)
namespace
py
=
pybind11
;
namespace
dlib
{
template
<
typename
T
>
py
::
tuple
getstate
(
const
T
&
item
)
{
using
namespace
dlib
;
std
::
vector
<
char
>
buf
;
buf
.
reserve
(
5000
);
...
...
@@ -18,11 +23,11 @@ py::tuple getstate(const T& item)
serialize
(
item
,
sout
);
return
py
::
make_tuple
(
py
::
handle
(
PyBytes_FromStringAndSize
(
buf
.
size
()
?&
buf
[
0
]
:
0
,
buf
.
size
())));
}
}
template
<
typename
T
>
T
setstate
(
py
::
tuple
state
)
{
template
<
typename
T
>
T
setstate
(
py
::
tuple
state
)
{
using
namespace
dlib
;
if
(
len
(
state
)
!=
1
)
{
...
...
@@ -60,6 +65,8 @@ T setstate(py::tuple state)
}
return
item
;
}
}
#endif // DLIB_SERIALIZE_PiCKLE_Hh_
...
...
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