def test_source(): A = Symbol('A') s = Source('s') assert s.name == 's' assert str(s.transform) == '1' assert str(s) == 's' s_q = Source('s', Symbol('Q')) assert s_q.name == 's' assert str(s_q.transform) == 'Q' assert str(s_q) == 'Q * s' assert str(s * 1.5) == '1.5 * s' assert str(s * A) == 'A * s' assert str(s_q * A) == '(Q * A) * s' assert str(1.5 * s) == '1.5 * s' assert str(A * s) == 'A * s' assert str(A * s_q) == '(Q * A) * s' assert str(-s) == '-1 * s' assert str(-(-s)) == 's' assert str(-s_q) == '-Q * s' assert str(s + s_q) == 's + Q * s' with pytest.raises(TypeError): s * "A"
def test_symbol(): A = Symbol('A') assert A.symbol == 'A' B = Symbol('B') assert str(B) == 'B' assert str(A + B) == '(A + B)' with pytest.raises(TypeError): A + "A" assert str(A - B) == '(A - B)' with pytest.raises(TypeError): A - [] assert str(A * B) == '(A * B)' assert str(A * 1) == 'A' assert str(1 * A) == 'A' assert str(1.0 * A) == 'A' assert str(A * 1.0) == 'A' assert str(A * 1.5) == '(A * 1.5)' assert str(A * 2) == '(A * 2)' assert str(A * Symbol('1')) == 'A' assert str(Symbol('1') * A) == 'A' with pytest.raises(TypeError): A * {} assert str(~A) == '~A' assert str(~(~A)) == 'A' assert str(-A) == '-A' assert str(-(-A)) == 'A' assert str(A * B + (B * ~A) * 0.5 - A) == '(((A * B) + ((B * ~A) * 0.5)) - A)'
def test_source(): A = Symbol("A") s = Source("s") assert s.name == "s" assert str(s.transform) == "1" assert str(s) == "s" s_q = Source("s", Symbol("Q")) assert s_q.name == "s" assert str(s_q.transform) == "Q" assert str(s_q) == "Q * s" assert str(s * 1.5) == "1.5 * s" assert str(s * A) == "A * s" assert str(s_q * A) == "(Q * A) * s" assert str(1.5 * s) == "1.5 * s" assert str(A * s) == "A * s" assert str(A * s_q) == "(Q * A) * s" assert str(-s) == "-1 * s" assert str(-(-s)) == "s" assert str(-s_q) == "-Q * s" assert str(s + s_q) == "s + Q * s" with pytest.raises(TypeError): s * "A"
def test_symbol(): A = Symbol("A") assert A.symbol == "A" B = Symbol("B") assert str(B) == "B" assert str(A + B) == "(A + B)" with pytest.raises(TypeError): A + "A" assert str(A - B) == "(A - B)" with pytest.raises(TypeError): A - [] assert str(A * B) == "(A * B)" assert str(A * 1) == "A" assert str(1 * A) == "A" assert str(1.0 * A) == "A" assert str(A * 1.0) == "A" assert str(A * 1.5) == "(A * 1.5)" assert str(A * 2) == "(A * 2)" assert str(A * Symbol("1")) == "A" assert str(Symbol("1") * A) == "A" with pytest.raises(TypeError): A * {} assert str(~A) == "~A" assert str(~(~A)) == "A" assert str(-A) == "-A" assert str(-(-A)) == "A" assert str(A * B + (B * ~A) * 0.5 - A) == "(((A * B) + ((B * ~A) * 0.5)) - A)"
def on_add(self, spa): Module.on_add(self, spa) self.spa = spa with spa: # connect basal ganglia to thalamus nengo.Connection(self.bg.output, self.actions.input, synapse=self.synapse_bg) # implement the various effects for i, action in enumerate(self.bg.actions.actions): for name, effects in iteritems(action.effect.effect): for effect in effects.expression.items: if isinstance(effect, (int, float)): effect = Symbol('%g' % effect) if isinstance(effect, Symbol): self.add_direct_effect(i, name, effect.symbol) elif isinstance(effect, Source): self.add_route_effect(i, name, effect.name, effect.transform.symbol, effect.inverted) elif isinstance(effect, Convolution): self.add_conv_effect(i, name, effect) else: raise NotImplementedError( "Subexpression '%s' from action '%s' is not " "supported by the Thalamus." % (effect, action))
def __getitem__(self, key): # this gets used by the eval in the constructor to create new # terms as needed item = self.objects.get(key, None) if item is None: if not key[0].isupper(): raise KeyError("Semantic pointers must begin with a capital") item = Symbol(key) self.objects[key] = item return item
import pytest from nengo.spa.action_objects import Symbol, Source, DotProduct A = Symbol('A') B = Symbol('B') x = Source('x') y = Source('y') def test_symbol(): A = Symbol('A') assert A.symbol == 'A' B = Symbol('B') assert str(B) == 'B' assert str(A + B) == '(A + B)' with pytest.raises(TypeError): A + "A" assert str(A - B) == '(A - B)' with pytest.raises(TypeError): A - [] assert str(A * B) == '(A * B)' assert str(A * 1) == 'A' assert str(1 * A) == 'A' assert str(1.0 * A) == 'A' assert str(A * 1.0) == 'A' assert str(A * 1.5) == '(A * 1.5)' assert str(A * 2) == '(A * 2)'
import pytest from nengo.exceptions import SpaParseError from nengo.spa.action_objects import Symbol, Source, DotProduct A = Symbol("A") B = Symbol("B") x = Source("x") y = Source("y") def test_symbol(): A = Symbol("A") assert A.symbol == "A" B = Symbol("B") assert str(B) == "B" assert str(A + B) == "(A + B)" with pytest.raises(TypeError): A + "A" assert str(A - B) == "(A - B)" with pytest.raises(TypeError): A - [] assert str(A * B) == "(A * B)" assert str(A * 1) == "A" assert str(1 * A) == "A" assert str(1.0 * A) == "A" assert str(A * 1.0) == "A" assert str(A * 1.5) == "(A * 1.5)"