Skip to content
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

Truncate semantic pointer names to 1 KB #246

Merged
merged 3 commits into from
Jun 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Release History
- ``SemanticPointer.translate`` and ``PointerSymbol.translate`` now use the ``keys``
argument; previously, this argument was mistakenly ignored.
(`#248 <https://github.com/nengo/nengo_spa/pull/248>`__)
- Fixed an issue where the names of iteratively generated semantic pointers
could grow exponentially in length, by truncating them at 1 KB.
(`#244 <https://github.com/nengo/nengo_spa/issues/244>`__,
`#246 <https://github.com/nengo/nengo_spa/pull/246>`__)


1.0.1 (December 14, 2019)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Licensed code
Nengo SPA imports several open source libraries.

* `NumPy <http://www.numpy.org/>`_ - Used under
`BSD license <http://www.numpy.org/license.html>`__
`BSD license <http://www.numpy.org/doc/stable/license.html>`__
* `Sphinx <http://www.sphinx-doc.org/en/master>`_ - Used under
`BSD license <https://bitbucket.org/birkenfeld/sphinx/src/be5bd373a1a47fb68d70523b6e980e654e070e9f/LICENSE?at=default>`__
* `nbsphinx <https://github.com/spatialaudio/nbsphinx>`_ - Used under
Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/spa-intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ example of an SPA to date.
nonlinear dynamical arm model). Central information manipulation depends on
syntaictic structure for several tasks. Control is largely captured by the
basal ganglia aciton selection elements. Memory and learning take place in
both basal ganglia and contex. The model itself consists of just under
both basal ganglia and cortex. The model itself consists of just under
a million spiking neurons.

Let us consider how the model would perform a single run of one of the cognitive
Expand Down
5 changes: 5 additions & 0 deletions nengo_spa/semantic_pointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class SemanticPointer(Fixed):
Name of the Semantic Pointer.
"""

MAX_NAME = 1024

def __init__(self, data, vocab=None, algebra=None, name=None):
super(SemanticPointer, self).__init__(
TAnyVocab if vocab is None else TVocabulary(vocab)
Expand All @@ -54,6 +56,9 @@ def __init__(self, data, vocab=None, algebra=None, name=None):
self.v.setflags(write=False)

self.vocab = vocab

if name is not None and len(name) > self.MAX_NAME:
name = "%s..." % (name[: self.MAX_NAME - 3])
self.name = name

def _get_algebra(cls, vocab, algebra):
Expand Down
6 changes: 6 additions & 0 deletions nengo_spa/tests/test_semantic_pointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@ def test_name():
assert (a + unnamed).name is None
assert (a * unnamed).name is None

# check that names that blow up exponentially in length are truncated
for i in range(10):
a += a * b
assert len(a.name) == a.MAX_NAME
assert a.name.endswith("...")


def test_translate(rng):
v1 = spa.Vocabulary(16, pointer_gen=rng)
Expand Down