File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
cpp_src/bindings/algorithms Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
181195if __name__ == "__main__" :
182196 unittest .main ()
You can’t perform that action at this time.
0 commit comments