forked from numenta/nupic.core-legacy
-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed pickling on SP #644
Merged
Fixed pickling on SP #644
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f7d5108
Fixed pickling on SP
dkeeney 9bb788b
Merge branch 'master' of https://github.com/htm-community/htm.core in…
dkeeney 4ad70af
Added the same changes to TM
dkeeney 2e1bb1e
copy paste error...fixed
dkeeney 46f8e39
more typing errors...must be getting tired
dkeeney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import pytest | ||
import pickle | ||
import sys | ||
import os | ||
|
||
from htm.bindings.sdr import SDR | ||
from htm.algorithms import TemporalMemory as TM | ||
|
@@ -38,15 +39,52 @@ def testCompute(self): | |
self.assertTrue( active.getSum() > 0 ) | ||
|
||
|
||
@pytest.mark.skipif(sys.version_info < (3, 6), reason="Fails for python2 with segmentation fault") | ||
def testNupicTemporalMemoryPickling(self): | ||
"""Test pickling / unpickling of NuPIC TemporalMemory.""" | ||
|
||
# Simple test: make sure that dumping / loading works... | ||
tm = TM(columnDimensions=(16,)) | ||
inputs = SDR( 100 ).randomize( .05 ) | ||
tm = TM( inputs.dimensions) | ||
for _ in range(10): | ||
tm.compute( inputs, True) | ||
|
||
pickledTm = pickle.dumps(tm) | ||
pickledTm = pickle.dumps(tm, 2) | ||
tm2 = pickle.loads(pickledTm) | ||
|
||
self.assertEqual(tm.numberOfCells(), tm2.numberOfCells(), | ||
"Simple NuPIC TemporalMemory pickle/unpickle failed.") | ||
|
||
|
||
@pytest.mark.skip(reason="Fails with rapidjson internal assertion -- indicates a bad serialization") | ||
def testNupicTemporalMemorySavingToString(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so, this is a new test, that fails - we think exposing an internal JSON/pybind bug. It's fine to skip in that case. |
||
"""Test writing to and reading from TemporalMemory.""" | ||
inputs = SDR( 100 ).randomize( .05 ) | ||
tm = TM( inputs.dimensions) | ||
for _ in range(10): | ||
tm.compute( inputs, True) | ||
|
||
# Simple test: make sure that writing/reading works... | ||
s = tm.writeToString() | ||
|
||
tm2 = TM() | ||
tm2.loadFromString(s) | ||
|
||
self.assertEqual(str(tm), str(tm), | ||
"TemporalMemory write to/read from string failed.") | ||
|
||
def testNupicTemporalMemorySerialization(self): | ||
# Test serializing with each type of interface. | ||
inputs = SDR( 100 ).randomize( .05 ) | ||
tm = TM( inputs.dimensions) | ||
for _ in range(10): | ||
tm.compute( inputs, True) | ||
|
||
#print(str(tm)) | ||
|
||
# The TM now has some data in it, try serialization. | ||
file = "temporalMemory_test_save2.bin" | ||
tm.saveToFile(file) | ||
tm3 = TM() | ||
tm3.loadFromFile(file) | ||
self.assertEqual(str(tm), str(tm3), "TemporalMemory serialization (using saveToFile/loadFromFile) failed.") | ||
os.remove(file) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this still valid? (we don't test on py2, but someone still may run the repo on python2)