From 78df1be51b8409053d76020d00ed479048406f5f Mon Sep 17 00:00:00 2001 From: Joffrey Gonin Date: Tue, 21 Feb 2017 14:00:04 +0100 Subject: [PATCH 1/5] Replace `pyNN.utility.assert_arrays_equal` by `numpy.testing.assert_array_equal` #267 and similarly for "almost_equal". --- pyNN/utility/__init__.py | 4 +-- test/system/scenarios/test_connectors.py | 23 +++++++++-------- .../scenarios/test_parameter_handling.py | 23 ++++++++--------- test/system/scenarios/test_procedural_api.py | 5 ++-- test/system/scenarios/test_recording.py | 25 ++++++++++--------- .../scenarios/test_simulation_control.py | 8 +++--- test/system/test_nest.py | 5 ++-- test/unittests/test_files.py | 5 ++-- test/unittests/test_random.py | 6 +++-- test/unittests/test_recording.py | 1 + test/unittests/test_space.py | 22 ++++++++-------- 11 files changed, 67 insertions(+), 60 deletions(-) diff --git a/pyNN/utility/__init__.py b/pyNN/utility/__init__.py index cab6706fb..5100a9b7e 100644 --- a/pyNN/utility/__init__.py +++ b/pyNN/utility/__init__.py @@ -373,7 +373,7 @@ def __call__(self, t): self.set_level(t / self.t_stop) return t + self.interval - +#deprecated def assert_arrays_equal(a, b): import numpy assert isinstance(a, numpy.ndarray), "a is a %s" % type(a) @@ -381,7 +381,7 @@ def assert_arrays_equal(a, b): assert a.shape == b.shape, "%s != %s" % (a, b) assert (a.flatten() == b.flatten()).all(), "%s != %s" % (a, b) - +#deprecated def assert_arrays_almost_equal(a, b, threshold): import numpy assert isinstance(a, numpy.ndarray), "a is a %s" % type(a) diff --git a/test/system/scenarios/test_connectors.py b/test/system/scenarios/test_connectors.py index 2aa51ae0c..034a59aa1 100644 --- a/test/system/scenarios/test_connectors.py +++ b/test/system/scenarios/test_connectors.py @@ -2,7 +2,8 @@ import numpy from nose.tools import assert_equal, assert_almost_equal from pyNN.random import NumpyRNG, RandomDistribution -from pyNN.utility import assert_arrays_equal, assert_arrays_almost_equal, connection_plot, init_logging +from pyNN.utility import connection_plot, init_logging +from numpy.testing import assert_array_equal, assert_array_almost_equal from .registry import register #init_logging(None, debug=True) @@ -21,7 +22,7 @@ def all_to_all_static_no_self(sim): print(weights) delays = prj.get('delay', format='list', gather=False) i, j, d = numpy.array(delays).T - assert_arrays_almost_equal(d, 0.2 + 0.3 * abs(i - j), 1e-9) + assert_array_almost_equal(d, 0.2 + 0.3 * abs(i - j), 1e-9) assert_equal(d.size, p.size * (p.size - 1)) sim.end() @@ -34,9 +35,9 @@ def all_to_all_tsodyksmarkram(sim): synapse_type = sim.TsodyksMarkramSynapse(weight=lambda d: d, delay=0.5, U=lambda d: 0.02 * d + 0.1) prj = sim.Projection(p1, p2, sim.AllToAllConnector(), synapse_type) i, j, w, d, u = numpy.array(prj.get(['weight', 'delay', 'U'], format='list', gather=False)).T - assert_arrays_equal(w, abs(i - j)) - assert_arrays_equal(d, 0.5 * numpy.ones(p2.size * p1.size)) - assert_arrays_equal(u, 0.02 * abs(i - j) + 0.1) + assert_array_equal(w, abs(i - j)) + assert_array_equal(d, 0.5 * numpy.ones(p2.size * p1.size)) + assert_array_equal(u, 0.02 * abs(i - j) + 0.1) weights, delays, U = prj.get(['weight', 'delay', 'U'], format='array', gather=False) print(weights) print(delays) # should all be 0.5 @@ -106,9 +107,9 @@ def fixed_number_pre_with_replacement_heterogeneous_parameters(sim): from pprint import pprint pprint(x) i, j, w, d, u = numpy.array(x).T - assert_arrays_equal(w, abs(i - j)) - assert_arrays_equal(d, 0.5 * numpy.ones(p2.size * connector1.n)) - assert_arrays_equal(u, 0.02 * abs(i - j) + 0.1) + assert_array_equal(w, abs(i - j)) + assert_array_equal(d, 0.5 * numpy.ones(p2.size * connector1.n)) + assert_array_equal(u, 0.02 * abs(i - j) + 0.1) sim.end() @@ -179,9 +180,9 @@ def fixed_number_post_with_replacement_heterogeneous_parameters(sim): from pprint import pprint pprint(x) i, j, w, d, u = numpy.array(x).T - assert_arrays_equal(w, abs(i - j)) - assert_arrays_equal(d, 0.5 * numpy.ones(p1.size * connector1.n)) - assert_arrays_equal(u, 0.02 * abs(i - j) + 0.1) + assert_array_equal(w, abs(i - j)) + assert_array_equal(d, 0.5 * numpy.ones(p1.size * connector1.n)) + assert_array_equal(u, 0.02 * abs(i - j) + 0.1) sim.end() diff --git a/test/system/scenarios/test_parameter_handling.py b/test/system/scenarios/test_parameter_handling.py index a9c955fab..b48d50c25 100644 --- a/test/system/scenarios/test_parameter_handling.py +++ b/test/system/scenarios/test_parameter_handling.py @@ -3,7 +3,6 @@ from numpy import nan from numpy.testing import assert_array_equal, assert_array_almost_equal from nose.tools import assert_equal -from pyNN.utility import assert_arrays_equal, assert_arrays_almost_equal from .registry import register @@ -16,7 +15,7 @@ def issue241(sim): spike_train3 = sim.Population(1, sim.SpikeSourcePoisson, {'rate': [5], 'start': [1000], 'duration': 1234}) spike_train4 = sim.Population(1, sim.SpikeSourcePoisson, {'rate': [5], 'start': [1000]}) spike_train5 = sim.Population(2, sim.SpikeSourcePoisson, {'rate': [5, 6], 'start': [1000, 1001]}) - assert_arrays_equal(spike_train2.get('duration'), numpy.array([1234, 2345])) + assert_array_equal(spike_train2.get('duration'), numpy.array([1234, 2345])) assert_equal(spike_train3.get(['rate', 'start', 'duration']), [5, 1000, 1234]) sim.end() @@ -58,28 +57,28 @@ def test_set_synaptic_parameters_fully_connected(sim): actual = numpy.array(prj.get(['weight', 'delay', 'U'], format='list')) if mpi_rank == 0: ind = numpy.lexsort((actual[:, 1], actual[:, 0])) - assert_arrays_almost_equal(actual[ind], expected, 1e-16) + assert_array_almost_equal(actual[ind], expected, 1e-16) positional_weights = numpy.array([[0, 1], [2, 3], [4, 5], [6, 7]], dtype=float) prj.set(weight=positional_weights) expected = positional_weights actual = prj.get('weight', format='array') if mpi_rank == 0: - assert_arrays_equal(actual, expected) + assert_array_equal(actual, expected) u_list = [0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2] prj.set(U=u_list) expected = numpy.array([[0.9, 0.8], [0.7, 0.6], [0.5, 0.4], [0.3, 0.2]]) actual = prj.get('U', format='array') if mpi_rank == 0: - assert_arrays_equal(actual, expected) + assert_array_equal(actual, expected) f_delay = lambda d: 0.5 + d prj.set(delay=f_delay) expected = numpy.array([[0.5, 1.5], [1.5, 0.5], [2.5, 1.5], [3.5, 2.5]]) actual = prj.get('delay', format='array') if mpi_rank == 0: - assert_arrays_equal(actual, expected) + assert_array_equal(actual, expected) # final sanity check expected = numpy.array([ @@ -95,7 +94,7 @@ def test_set_synaptic_parameters_fully_connected(sim): actual = numpy.array(prj.get(['weight', 'delay', 'U'], format='list')) if mpi_rank == 0: ind = numpy.lexsort((actual[:, 1], actual[:, 0])) - assert_arrays_equal(actual[ind], expected) + assert_array_equal(actual[ind], expected) test_set_synaptic_parameters_fully_connected.__test__ = False @@ -118,7 +117,7 @@ def test_set_synaptic_parameters_partially_connected(sim): actual = numpy.array(prj.get(['weight', 'delay', 'U'], format='list')) if mpi_rank == 0: ind = numpy.lexsort((actual[:, 1], actual[:, 0])) - assert_arrays_almost_equal(actual[ind], expected, 1e-16) + assert_array_almost_equal(actual[ind], expected, 1e-16) positional_weights = numpy.array([[0, nan], [2, 3], [nan, 5], [6, nan]], dtype=float) prj.set(weight=positional_weights) @@ -176,7 +175,7 @@ def test_set_synaptic_parameters_multiply_connected(sim): actual = numpy.array(prj.get(['weight', 'delay', 'U'], format='list')) if mpi_rank == 0: ind = numpy.lexsort((actual[:, 1], actual[:, 0])) - assert_arrays_almost_equal(actual[ind], expected, 1e-16) + assert_array_almost_equal(actual[ind], expected, 1e-16) positional_weights = numpy.array([[0, nan], [2, 3], [nan, 5], [6, nan]], dtype=float) prj.set(weight=positional_weights) @@ -191,7 +190,7 @@ def test_set_synaptic_parameters_multiply_connected(sim): actual = numpy.array(prj.get('weight', format='list')) if mpi_rank == 0: ind = numpy.lexsort((actual[:, 1], actual[:, 0])) - assert_arrays_almost_equal(actual[ind], expected, 1e-16) + assert_array_almost_equal(actual[ind], expected, 1e-16) # postponing implementation of this functionality until after 0.8.0 # u_list = [0.9, 0.8, 0.7, 0.6, 0.5, 0.4] @@ -207,7 +206,7 @@ def test_set_synaptic_parameters_multiply_connected(sim): # actual = numpy.array(prj.get('U', format='list')) # if mpi_rank == 0: # ind = numpy.lexsort((actual[:, 1], actual[:, 0])) - # assert_arrays_almost_equal(actual[ind], expected, 1e-16) + # assert_array_almost_equal(actual[ind], expected, 1e-16) f_delay = lambda d: 0.5 + d prj.set(delay=f_delay) @@ -222,7 +221,7 @@ def test_set_synaptic_parameters_multiply_connected(sim): actual = numpy.array(prj.get('delay', format='list')) if mpi_rank == 0: ind = numpy.lexsort((actual[:, 1], actual[:, 0])) - assert_arrays_almost_equal(actual[ind], expected, 1e-16) + assert_array_almost_equal(actual[ind], expected, 1e-16) # final sanity check expected = numpy.array([ diff --git a/test/system/scenarios/test_procedural_api.py b/test/system/scenarios/test_procedural_api.py index 742d3cfa4..b79f5bd7e 100644 --- a/test/system/scenarios/test_procedural_api.py +++ b/test/system/scenarios/test_procedural_api.py @@ -1,7 +1,8 @@ import numpy import quantities as pq -from pyNN.utility import init_logging, assert_arrays_almost_equal +from pyNN.utility import init_logging +from numpy.testing import assert_array_equal, assert_array_almost_equal from .registry import register @@ -20,7 +21,7 @@ def ticket195(sim): #prj = sim.Projection(pre, post, sim.FromListConnector([(0, 0, 0.01, 0.1)])) post.record(['spikes', 'v']) sim.run(100.0) - assert_arrays_almost_equal(post.get_data().segments[0].spiketrains[0], numpy.array([13.4]) * pq.ms, 0.5) + assert_array_almost_equal(post.get_data().segments[0].spiketrains[0], numpy.array([13.4]) * pq.ms, 0.5) sim.end() if __name__ == '__main__': diff --git a/test/system/scenarios/test_recording.py b/test/system/scenarios/test_recording.py index 53c0a0333..9117564ca 100644 --- a/test/system/scenarios/test_recording.py +++ b/test/system/scenarios/test_recording.py @@ -4,7 +4,8 @@ import quantities as pq from nose.tools import assert_equal from neo.io import get_io -from pyNN.utility import assert_arrays_equal, assert_arrays_almost_equal, init_logging +from pyNN.utility import init_logging +from numpy.testing import assert_array_equal, assert_array_almost_equal from .registry import register @@ -31,7 +32,7 @@ def test_reset_recording(sim): data = p.get_data() sim.end() ti = lambda i: data.segments[i].analogsignalarrays[0].times - assert_arrays_equal(ti(0), ti(1)) + assert_array_equal(ti(0), ti(1)) idx = lambda i: data.segments[i].analogsignalarrays[0].channel_index assert idx(0) == [3] assert idx(1) == [4] @@ -79,14 +80,14 @@ def test_record_vm_and_gsyn_from_assembly(sim): assert_equal(gsyn_p1.shape, (n_points, 4)) assert_equal(gsyn_all.shape, (n_points, 7)) - assert_arrays_equal(vm_p1[:, 3], vm_all[:, 8]) + assert_array_equal(vm_p1[:, 3], vm_all[:, 8]) - assert_arrays_equal(vm_p0.channel_index, numpy.arange(5)) - assert_arrays_equal(vm_p1.channel_index, numpy.arange(6)) - assert_arrays_equal(vm_all.channel_index, numpy.arange(11)) - assert_arrays_equal(gsyn_p0.channel_index, numpy.array([2, 3, 4])) - assert_arrays_equal(gsyn_p1.channel_index, numpy.arange(4)) - assert_arrays_equal(gsyn_all.channel_index, numpy.arange(2, 9)) + assert_array_equal(vm_p0.channel_index, numpy.arange(5)) + assert_array_equal(vm_p1.channel_index, numpy.arange(6)) + assert_array_equal(vm_all.channel_index, numpy.arange(11)) + assert_array_equal(gsyn_p0.channel_index, numpy.array([2, 3, 4])) + assert_array_equal(gsyn_p1.channel_index, numpy.arange(4)) + assert_array_equal(gsyn_all.channel_index, numpy.arange(2, 9)) sim.end() test_record_vm_and_gsyn_from_assembly.__test__ = False @@ -111,8 +112,8 @@ def issue259(sim): print(spiketrains2[0]) sim.end() - assert_arrays_almost_equal(spiketrains0[0], numpy.array([0.075]) * pq.ms, 1e-17) - assert_arrays_almost_equal(spiketrains1[0], numpy.array([10.025, 12.34]) * pq.ms, 1e-14) + assert_array_almost_equal(spiketrains0[0], numpy.array([0.075]) * pq.ms, 1e-17) + assert_array_almost_equal(spiketrains1[0], numpy.array([10.025, 12.34]) * pq.ms, 1e-14) assert_equal(spiketrains2[0].size, 0) @@ -151,7 +152,7 @@ def test_mix_procedural_and_oo(sim): data_proc = get_io(fn_proc).read()[0] data_oo = get_io(fn_oo).read()[0] - assert_arrays_equal(data_proc.segments[0].analogsignalarrays[0], + assert_array_equal(data_proc.segments[0].analogsignalarrays[0], data_oo.segments[0].analogsignalarrays[0]) os.remove(fn_proc) diff --git a/test/system/scenarios/test_simulation_control.py b/test/system/scenarios/test_simulation_control.py index 3b5c3846b..bfa1a4ace 100644 --- a/test/system/scenarios/test_simulation_control.py +++ b/test/system/scenarios/test_simulation_control.py @@ -1,6 +1,6 @@ from nose.tools import assert_almost_equal, assert_raises -from pyNN.utility import assert_arrays_equal, assert_arrays_almost_equal +from numpy.testing import assert_array_equal, assert_array_almost_equal from .registry import register @@ -24,7 +24,7 @@ def test_reset(sim): assert len(data.segments) == repeats for segment in data.segments[1:]: - assert_arrays_almost_equal(segment.analogsignalarrays[0], + assert_array_almost_equal(segment.analogsignalarrays[0], data.segments[0].analogsignalarrays[0], 1e-11) test_reset.__test__ = False @@ -51,7 +51,7 @@ def test_reset_with_clear(sim): for rec in data: assert len(rec.segments) == 1 - assert_arrays_almost_equal(rec.segments[0].analogsignalarrays[0], + assert_array_almost_equal(rec.segments[0].analogsignalarrays[0], data[0].segments[0].analogsignalarrays[0], 1e-11) test_reset_with_clear.__test__ = False @@ -79,7 +79,7 @@ def test_setup(sim): assert len(block.segments) == 1 signals = block.segments[0].analogsignalarrays assert len(signals) == 1 - assert_arrays_equal(signals[0], data[0].segments[0].analogsignalarrays[0]) + assert_array_equal(signals[0], data[0].segments[0].analogsignalarrays[0]) test_setup.__test__ = False diff --git a/test/system/test_nest.py b/test/system/test_nest.py index 290d122bb..0b80a41a2 100644 --- a/test/system/test_nest.py +++ b/test/system/test_nest.py @@ -2,6 +2,7 @@ from .scenarios.registry import registry from nose.tools import assert_equal, assert_not_equal from pyNN.utility import init_logging, assert_arrays_equal +from numpy.testing import assert_array_equal, assert_array_almost_equal import numpy try: @@ -36,7 +37,7 @@ def test_record_native_model(): p1 = nest.Population(n_cells, nest.native_cell_type("ht_neuron")(**parameters)) p1.initialize(V_m=-70.0, Theta=-50.0) p1.set(Theta_eq=-51.5) - #assert_arrays_equal(p1.get('Theta_eq'), -51.5*numpy.ones((10,))) + #assert_array_equal(p1.get('Theta_eq'), -51.5*numpy.ones((10,))) assert_equal(p1.get('Theta_eq'), -51.5) print(p1.get('Tau_m')) p1.set(Tau_m=RandomDistribution('uniform', low=15.0, high=20.0)) @@ -181,7 +182,7 @@ def test_tsodyks_markram_synapse(): sim.run(100.0) connections = nest.GetConnections(prj._sources.tolist(), synapse_model=prj.nest_synapse_model) tau_psc = numpy.array(nest.GetStatus(connections, 'tau_psc')) - assert_arrays_equal(tau_psc, numpy.arange(0.2, 0.7, 0.1)) + assert_array_equal(tau_psc, numpy.arange(0.2, 0.7, 0.1)) if __name__ == '__main__': diff --git a/test/unittests/test_files.py b/test/unittests/test_files.py index 685f38f86..32712f0ce 100644 --- a/test/unittests/test_files.py +++ b/test/unittests/test_files.py @@ -8,6 +8,7 @@ import numpy import os from pyNN.utility import assert_arrays_equal +from numpy.testing import assert_array_equal, assert_array_almost_equal builtin_open = open @@ -99,7 +100,7 @@ def test_PickleFile(): # # nbf = files.NumpyBinaryFile("tmp.npz", "r") # assert_equal(nbf.get_metadata(), metadata) -# assert_arrays_equal(nbf.read().flatten(), numpy.array(data).flatten()) +# assert_array_equal(nbf.read().flatten(), numpy.array(data).flatten()) # nbf.close() # # os.remove("tmp.npz") @@ -115,7 +116,7 @@ def test_HDF5ArrayFile(): h5f = files.HDF5ArrayFile("tmp.h5", "r") assert_equal(h5f.get_metadata(), metadata) - assert_arrays_equal(numpy.array(h5f.read()).flatten(), + assert_array_equal(numpy.array(h5f.read()).flatten(), numpy.array(data).flatten()) h5f.close() diff --git a/test/unittests/test_random.py b/test/unittests/test_random.py index 70430d203..3cf75b4fc 100644 --- a/test/unittests/test_random.py +++ b/test/unittests/test_random.py @@ -17,8 +17,10 @@ have_nrn = True from pyNN.neuron.random import NativeRNG +from numpy.testing import assert_array_equal, assert_array_almost_equal -def assert_arrays_almost_equal(a, b, threshold): +#deprecated +def assert_arrays_almost_equal(a, b, threshold): if not (abs(a - b) < threshold).all(): err_msg = "%s != %s" % (a, b) err_msg += "\nlargest difference = %g" % abs(a - b).max() @@ -129,7 +131,7 @@ def test_permutation(self): A = range(10) perm0 = rng0.permutation(A) perm1 = rng1.permutation(A) - assert_arrays_almost_equal(perm0, perm1, 1e-99) + assert_array_almost_equal(perm0, perm1, 1e-99) class NativeRNGTests(unittest.TestCase): diff --git a/test/unittests/test_recording.py b/test/unittests/test_recording.py index 728be2809..48f73fd92 100644 --- a/test/unittests/test_recording.py +++ b/test/unittests/test_recording.py @@ -9,6 +9,7 @@ from datetime import datetime from collections import defaultdict from pyNN.utility import assert_arrays_equal +from numpy.testing import assert_array_equal #def test_rename_existing(): diff --git a/test/unittests/test_space.py b/test/unittests/test_space.py index f78b39513..dea42cb68 100644 --- a/test/unittests/test_space.py +++ b/test/unittests/test_space.py @@ -13,10 +13,10 @@ except ImportError: from mock import Mock from nose.tools import assert_equal, assert_raises -from pyNN.utility import assert_arrays_equal +from numpy.testing import assert_array_equal, assert_array_almost_equal from math import sqrt - +#deprecated def assert_arrays_almost_equal(a, b, threshold, msg=''): if a.shape != b.shape: raise unittest.TestCase.failureException("Shape mismatch: a.shape=%s, b.shape=%s" % (a.shape, b.shape)) @@ -74,7 +74,7 @@ def test_infinite_space_with_3D_distances(self): numpy.array([0.0, sqrt(3), sqrt(3), sqrt(29)])) self.assertArraysEqual(s.distances(self.A, self.ABCD), s.distances(self.ABCD, self.A).T) - assert_arrays_equal(s.distances(self.ABCD, self.ABCD), + assert_array_equal(s.distances(self.ABCD, self.ABCD), numpy.array([0.0, sqrt(3), sqrt(3), sqrt(29), sqrt(3), 0.0, sqrt(12), sqrt(14), sqrt(3), sqrt(12), 0.0, sqrt(50.0), @@ -88,7 +88,7 @@ def test_generator_for_infinite_space_with_3D_distances(self): g = lambda j: self.ABCD[j] self.assertArraysEqual(s.distance_generator(f, g)(0, numpy.arange(4)), numpy.array([0.0, sqrt(3), sqrt(3), sqrt(29)])) - assert_arrays_equal(numpy.fromfunction(s.distance_generator(f, g), shape=(4, 4), dtype=int), + assert_array_equal(numpy.fromfunction(s.distance_generator(f, g), shape=(4, 4), dtype=int), numpy.array([(0.0, sqrt(3), sqrt(3), sqrt(29)), (sqrt(3), 0.0, sqrt(12), sqrt(14)), (sqrt(3), sqrt(12), 0.0, sqrt(50.0)), @@ -135,10 +135,10 @@ def test_generate_positions_default_parameters(self): n = 4 positions = line.generate_positions(n) assert_equal(positions.shape, (3, n)) - assert_arrays_almost_equal( + assert_array_almost_equal( positions, numpy.array([[0, 0, 0], [1, 0, 0], [2, 0, 0], [3, 0, 0]], float).T, - threshold=1e-15 + decimal=15 ) def test_generate_positions(self): @@ -146,10 +146,10 @@ def test_generate_positions(self): n = 2 positions = line.generate_positions(n) assert_equal(positions.shape, (3, n)) - assert_arrays_almost_equal( + assert_array_almost_equal( positions, numpy.array([[-100, 444, 987], [0, 444, 987]], float).T, - threshold=1e-15 + decimal=15 ) def test__eq__(self): @@ -185,14 +185,14 @@ def test_generate_positions(self): n = 4 positions = self.grid1.generate_positions(n) assert_equal(positions.shape, (3, n)) - assert_arrays_almost_equal( + assert_array_almost_equal( positions, numpy.array([ [0, 0, 0], [0, 1, 0], [1, 0, 0], [1, 1, 0] ]).T, 1e-15) - assert_arrays_almost_equal( + assert_array_almost_equal( self.grid2.generate_positions(12), numpy.array([ [123, 456, 789], [123, 465.9, 789], @@ -227,7 +227,7 @@ def test_generate_positions(self): n = 8 positions = self.grid1.generate_positions(n) assert_equal(positions.shape, (3, n)) - assert_arrays_almost_equal( + assert_array_almost_equal( positions, numpy.array([ [0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], From e1b61386d4cab404794e32b60b4bd3cde9341e8d Mon Sep 17 00:00:00 2001 From: Joffrey Gonin Date: Mon, 6 Mar 2017 15:05:18 +0100 Subject: [PATCH 2/5] blank line for travis test --- pyNN/utility/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyNN/utility/__init__.py b/pyNN/utility/__init__.py index 5100a9b7e..4e66f6536 100644 --- a/pyNN/utility/__init__.py +++ b/pyNN/utility/__init__.py @@ -373,6 +373,7 @@ def __call__(self, t): self.set_level(t / self.t_stop) return t + self.interval + #deprecated def assert_arrays_equal(a, b): import numpy From 94140ad9b4dd9a8939d16971571a5309dc0146e1 Mon Sep 17 00:00:00 2001 From: Joffrey Gonin Date: Mon, 6 Mar 2017 15:42:12 +0100 Subject: [PATCH 3/5] change 1e-15 by decimal=15 in assert_array_almost_equal() --- test/unittests/test_space.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unittests/test_space.py b/test/unittests/test_space.py index dea42cb68..79fb02614 100644 --- a/test/unittests/test_space.py +++ b/test/unittests/test_space.py @@ -191,7 +191,7 @@ def test_generate_positions(self): [0, 0, 0], [0, 1, 0], [1, 0, 0], [1, 1, 0] ]).T, - 1e-15) + decimal=15) assert_array_almost_equal( self.grid2.generate_positions(12), numpy.array([ @@ -202,7 +202,7 @@ def test_generate_positions(self): [123 + 44.4, 456, 789], [123 + 44.4, 465.9, 789], [123 + 55.5, 456, 789], [123 + 55.5, 465.9, 789], ]).T, - 1e-15) + decimal=15) class Grid3D_Test(object): @@ -233,7 +233,7 @@ def test_generate_positions(self): [0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1] ]).T, - 1e-15) + decimal=15) class TestSphere(object): From 318d3a4752c4bb03b985a64619a448dcaf23cb6a Mon Sep 17 00:00:00 2001 From: Joffrey Gonin Date: Mon, 6 Mar 2017 16:03:04 +0100 Subject: [PATCH 4/5] change 1e- by decimal= in all assert_array_almost_equal() call during tests --- test/system/scenarios/test_connectors.py | 2 +- test/system/scenarios/test_parameter_handling.py | 10 +++++----- test/system/scenarios/test_recording.py | 4 ++-- test/system/scenarios/test_simulation_control.py | 4 ++-- test/unittests/test_random.py | 2 +- test/unittests/test_space.py | 6 +++--- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/system/scenarios/test_connectors.py b/test/system/scenarios/test_connectors.py index 034a59aa1..4921d94f9 100644 --- a/test/system/scenarios/test_connectors.py +++ b/test/system/scenarios/test_connectors.py @@ -22,7 +22,7 @@ def all_to_all_static_no_self(sim): print(weights) delays = prj.get('delay', format='list', gather=False) i, j, d = numpy.array(delays).T - assert_array_almost_equal(d, 0.2 + 0.3 * abs(i - j), 1e-9) + assert_array_almost_equal(d, 0.2 + 0.3 * abs(i - j), decimal=9) # 1e-9) assert_equal(d.size, p.size * (p.size - 1)) sim.end() diff --git a/test/system/scenarios/test_parameter_handling.py b/test/system/scenarios/test_parameter_handling.py index b48d50c25..5e27d58c3 100644 --- a/test/system/scenarios/test_parameter_handling.py +++ b/test/system/scenarios/test_parameter_handling.py @@ -57,7 +57,7 @@ def test_set_synaptic_parameters_fully_connected(sim): actual = numpy.array(prj.get(['weight', 'delay', 'U'], format='list')) if mpi_rank == 0: ind = numpy.lexsort((actual[:, 1], actual[:, 0])) - assert_array_almost_equal(actual[ind], expected, 1e-16) + assert_array_almost_equal(actual[ind], expected, decimal=16) positional_weights = numpy.array([[0, 1], [2, 3], [4, 5], [6, 7]], dtype=float) prj.set(weight=positional_weights) @@ -117,7 +117,7 @@ def test_set_synaptic_parameters_partially_connected(sim): actual = numpy.array(prj.get(['weight', 'delay', 'U'], format='list')) if mpi_rank == 0: ind = numpy.lexsort((actual[:, 1], actual[:, 0])) - assert_array_almost_equal(actual[ind], expected, 1e-16) + assert_array_almost_equal(actual[ind], expected, decimal=16) positional_weights = numpy.array([[0, nan], [2, 3], [nan, 5], [6, nan]], dtype=float) prj.set(weight=positional_weights) @@ -175,7 +175,7 @@ def test_set_synaptic_parameters_multiply_connected(sim): actual = numpy.array(prj.get(['weight', 'delay', 'U'], format='list')) if mpi_rank == 0: ind = numpy.lexsort((actual[:, 1], actual[:, 0])) - assert_array_almost_equal(actual[ind], expected, 1e-16) + assert_array_almost_equal(actual[ind], expected, decimal=16) positional_weights = numpy.array([[0, nan], [2, 3], [nan, 5], [6, nan]], dtype=float) prj.set(weight=positional_weights) @@ -190,7 +190,7 @@ def test_set_synaptic_parameters_multiply_connected(sim): actual = numpy.array(prj.get('weight', format='list')) if mpi_rank == 0: ind = numpy.lexsort((actual[:, 1], actual[:, 0])) - assert_array_almost_equal(actual[ind], expected, 1e-16) + assert_array_almost_equal(actual[ind], expected, decimal=16) # postponing implementation of this functionality until after 0.8.0 # u_list = [0.9, 0.8, 0.7, 0.6, 0.5, 0.4] @@ -221,7 +221,7 @@ def test_set_synaptic_parameters_multiply_connected(sim): actual = numpy.array(prj.get('delay', format='list')) if mpi_rank == 0: ind = numpy.lexsort((actual[:, 1], actual[:, 0])) - assert_array_almost_equal(actual[ind], expected, 1e-16) + assert_array_almost_equal(actual[ind], expected, decimal=16) # final sanity check expected = numpy.array([ diff --git a/test/system/scenarios/test_recording.py b/test/system/scenarios/test_recording.py index 9117564ca..9fe7c0f8f 100644 --- a/test/system/scenarios/test_recording.py +++ b/test/system/scenarios/test_recording.py @@ -112,8 +112,8 @@ def issue259(sim): print(spiketrains2[0]) sim.end() - assert_array_almost_equal(spiketrains0[0], numpy.array([0.075]) * pq.ms, 1e-17) - assert_array_almost_equal(spiketrains1[0], numpy.array([10.025, 12.34]) * pq.ms, 1e-14) + assert_array_almost_equal(spiketrains0[0], numpy.array([0.075]) * pq.ms, decimal=17) + assert_array_almost_equal(spiketrains1[0], numpy.array([10.025, 12.34]) * pq.ms, decimal=14) assert_equal(spiketrains2[0].size, 0) diff --git a/test/system/scenarios/test_simulation_control.py b/test/system/scenarios/test_simulation_control.py index bfa1a4ace..53064eed3 100644 --- a/test/system/scenarios/test_simulation_control.py +++ b/test/system/scenarios/test_simulation_control.py @@ -25,7 +25,7 @@ def test_reset(sim): assert len(data.segments) == repeats for segment in data.segments[1:]: assert_array_almost_equal(segment.analogsignalarrays[0], - data.segments[0].analogsignalarrays[0], 1e-11) + data.segments[0].analogsignalarrays[0], decimal=11) test_reset.__test__ = False @@ -52,7 +52,7 @@ def test_reset_with_clear(sim): for rec in data: assert len(rec.segments) == 1 assert_array_almost_equal(rec.segments[0].analogsignalarrays[0], - data[0].segments[0].analogsignalarrays[0], 1e-11) + data[0].segments[0].analogsignalarrays[0], decimal=11) test_reset_with_clear.__test__ = False diff --git a/test/unittests/test_random.py b/test/unittests/test_random.py index 3cf75b4fc..9d935740c 100644 --- a/test/unittests/test_random.py +++ b/test/unittests/test_random.py @@ -131,7 +131,7 @@ def test_permutation(self): A = range(10) perm0 = rng0.permutation(A) perm1 = rng1.permutation(A) - assert_array_almost_equal(perm0, perm1, 1e-99) + assert_array_almost_equal(perm0, perm1, decimal=99) class NativeRNGTests(unittest.TestCase): diff --git a/test/unittests/test_space.py b/test/unittests/test_space.py index dea42cb68..79fb02614 100644 --- a/test/unittests/test_space.py +++ b/test/unittests/test_space.py @@ -191,7 +191,7 @@ def test_generate_positions(self): [0, 0, 0], [0, 1, 0], [1, 0, 0], [1, 1, 0] ]).T, - 1e-15) + decimal=15) assert_array_almost_equal( self.grid2.generate_positions(12), numpy.array([ @@ -202,7 +202,7 @@ def test_generate_positions(self): [123 + 44.4, 456, 789], [123 + 44.4, 465.9, 789], [123 + 55.5, 456, 789], [123 + 55.5, 465.9, 789], ]).T, - 1e-15) + decimal=15) class Grid3D_Test(object): @@ -233,7 +233,7 @@ def test_generate_positions(self): [0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1] ]).T, - 1e-15) + decimal=15) class TestSphere(object): From 893f0c771e0cbf6bbb617a412601908d1ff22f14 Mon Sep 17 00:00:00 2001 From: Joffrey Gonin Date: Mon, 6 Mar 2017 17:19:51 +0100 Subject: [PATCH 5/5] One error corrected in test_procedural_api --- test/system/scenarios/test_procedural_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/scenarios/test_procedural_api.py b/test/system/scenarios/test_procedural_api.py index b79f5bd7e..e66604963 100644 --- a/test/system/scenarios/test_procedural_api.py +++ b/test/system/scenarios/test_procedural_api.py @@ -21,7 +21,7 @@ def ticket195(sim): #prj = sim.Projection(pre, post, sim.FromListConnector([(0, 0, 0.01, 0.1)])) post.record(['spikes', 'v']) sim.run(100.0) - assert_array_almost_equal(post.get_data().segments[0].spiketrains[0], numpy.array([13.4]) * pq.ms, 0.5) + assert_array_almost_equal(post.get_data().segments[0].spiketrains[0], numpy.array([13.4]) * pq.ms, decimal=1) sim.end() if __name__ == '__main__':