Skip to content

Commit 247fb24

Browse files
Merge branch 'master' into conn_opt
2 parents e1e856c + 67ea049 commit 247fb24

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

bindings/py/cpp_src/bindings/algorithms/py_SpatialPooler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ Argument wrapAround boolean value that determines whether or not inputs
246246
py_SpatialPooler.def("setMinPctOverlapDutyCycles", &SpatialPooler::setMinPctOverlapDutyCycles);
247247

248248
// loadFromString
249-
py_SpatialPooler.def("loadFromString", [](SpatialPooler& self, const std::string& inString)
249+
py_SpatialPooler.def("loadFromString", [](SpatialPooler& self, const py::bytes& inString)
250250
{
251-
std::istringstream inStream(inString);
251+
std::stringstream inStream(inString.cast<std::string>());
252252
self.load(inStream);
253253
});
254254

@@ -261,7 +261,7 @@ Argument wrapAround boolean value that determines whether or not inputs
261261

262262
self.save(os);
263263

264-
return os.str();
264+
return py::bytes( os.str() );
265265
});
266266

267267
// compute

bindings/py/tests/algorithms/spatial_pooler_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,20 @@ def testNupicSpatialPoolerPickling(self):
177177
self.assertEqual(sp.getNumColumns(), sp2.getNumColumns(),
178178
"Simple NuPIC SpatialPooler pickle/unpickle failed.")
179179

180+
def testNupicSpatialPoolerSavingToString(self):
181+
"""Test writing to and reading from NuPIC SpatialPooler."""
182+
183+
# Simple test: make sure that writing/reading works...
184+
sp = SP()
185+
s = sp.writeToString()
186+
187+
sp2 = SP(columnDimensions=[32, 32])
188+
sp2.loadFromString(s)
189+
190+
self.assertEqual(sp.getNumColumns(), sp2.getNumColumns(),
191+
"NuPIC SpatialPooler write to/read from string failed.")
192+
193+
180194

181195
if __name__ == "__main__":
182196
unittest.main()

0 commit comments

Comments
 (0)