Skip to content

Commit

Permalink
Use bytes on pickle SpatialPooler and TemporalMemory
Browse files Browse the repository at this point in the history
  • Loading branch information
Lupino committed Jun 26, 2019
1 parent 69555d7 commit d749c95
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions bindings/py/cpp_src/bindings/algorithms/py_SpatialPooler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,11 @@ Argument output An SDR representing the winning columns after

sp.save(ss);

return ss.str();
return py::bytes( ss.str() );
},
[](std::string& s)
[](py::bytes &s)
{
std::istringstream ss(s);
std::stringstream ss( s.cast<std::string>() );
SpatialPooler sp;
sp.load(ss);

Expand Down
10 changes: 5 additions & 5 deletions bindings/py/cpp_src/bindings/algorithms/py_TemporalMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Argument externalPredictiveInputs
// pickle
// https://github.com/pybind/pybind11/issues/1061
py_HTM.def(py::pickle(
[](const HTM_t& self) -> std::string
[](const HTM_t& self)
{
// __getstate__
std::ostringstream os;
Expand All @@ -160,17 +160,17 @@ Argument externalPredictiveInputs

self.save(os);

return os.str();
return py::bytes(os.str());
},
[](const std::string& str) -> HTM_t
[](const py::bytes &str)
{
// __setstate__
if (str.empty())
if (py::len(str) == 0)
{
throw std::runtime_error("Empty state");
}

std::istringstream is(str);
std::stringstream is( str.cast<std::string>() );

HTM_t htm;
htm.load(is);
Expand Down

0 comments on commit d749c95

Please sign in to comment.