Skip to content

Commit

Permalink
[SYNC] Update PES test any Synapse compare to Nengo #1095
Browse files Browse the repository at this point in the history
  • Loading branch information
arvoelke committed Jun 15, 2016
1 parent e9dfac9 commit a011448
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
10 changes: 6 additions & 4 deletions nengolib/signal/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def sys_equal(sys1, sys2, rtol=1e-05, atol=1e-08):
sys1 = LinearSystem(sys1)
sys2 = LinearSystem(sys2)
if sys1.analog != sys2.analog:
raise ValueError("cannot compare analog with discrete system")
raise ValueError("Cannot compare analog with discrete system")
tf1 = normalize(*sys2tf(sys1))
tf2 = normalize(*sys2tf(sys2))
for t1, t2 in zip(tf1, tf2):
Expand All @@ -144,7 +144,7 @@ def ss_equal(sys1, sys2, rtol=1e-05, atol=1e-08):
sys1 = LinearSystem(sys1)
sys2 = LinearSystem(sys2)
if sys1.analog != sys2.analog:
raise ValueError("cannot compare analog with discrete system")
raise ValueError("Cannot compare analog with discrete system")
return (np.allclose(sys1.A, sys2.A, rtol=rtol, atol=atol) and
np.allclose(sys1.B, sys2.B, rtol=rtol, atol=atol) and
np.allclose(sys1.C, sys2.C, rtol=rtol, atol=atol) and
Expand Down Expand Up @@ -430,8 +430,10 @@ def __rtruediv__(self, other):
return self.__rdiv__(other)

def __eq__(self, other):
self._check_other(other)
return sys_equal(self.tf, LinearSystem(other, self.analog).tf)
if isinstance(other, LinearFilter): # base class containing analog
if self.analog != other.analog:
return False
return sys_equal(self, other)

def __ne__(self, other):
return not self.__eq__(other)
Expand Down
8 changes: 6 additions & 2 deletions nengolib/signal/tests/test_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ def test_pes_learning_rate(Simulator, plt, seed):
stim = nengo.Node(output=initial)
ystar = nengo.Node(output=desired)

conn.learning_rule_type = nengo.PES(
pre_tau=1e-15, learning_rate=learning_rate)
try:
conn.learning_rule_type = nengo.PES(
pre_synapse=None, learning_rate=learning_rate)
except TypeError: # prior to Nengo PR #1095
conn.learning_rule_type = nengo.PES(
pre_tau=1e-15, learning_rate=learning_rate)

nengo.Connection(stim, x, synapse=None)
nengo.Connection(ystar, conn.learning_rule, synapse=0, transform=-1)
Expand Down
14 changes: 6 additions & 8 deletions nengolib/signal/tests/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ def test_sys_conversions():
def test_check_sys_equal():
assert not sys_equal(np.zeros(2), np.zeros(3))

assert s != z
assert not z == s
assert LinearSystem(5, analog=True) != LinearSystem(5, analog=False)

with pytest.raises(ValueError):
assert not sys_equal(s, z)
sys_equal(s, z)

with pytest.raises(ValueError):
assert not ss_equal(s, z)
ss_equal(s, z)


def test_canonical():
Expand Down Expand Up @@ -306,12 +310,6 @@ def test_linear_system_type():


def test_invalid_operations():
with pytest.raises(ValueError):
z == s

with pytest.raises(ValueError):
s != z

with pytest.raises(ValueError):
z + s

Expand Down

0 comments on commit a011448

Please sign in to comment.