Skip to content

Commit efb7bb7

Browse files
authored
update tests (#169)
update tests
2 parents 5569c6c + 71e0874 commit efb7bb7

File tree

14 files changed

+63
-27
lines changed

14 files changed

+63
-27
lines changed

brainpy/analysis/lowdim/tests/test_phase_plane.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import unittest
44

55
import brainpy as bp
6-
import matplotlib.pyplot as plt
76

87
block = False
98

109

1110
class TestPhasePlane(unittest.TestCase):
1211
def test_1d(self):
12+
import matplotlib.pyplot as plt
1313
bp.math.enable_x64()
14+
1415
@bp.odeint
1516
def int_x(x, t, Iext):
1617
dx = x ** 3 - x + Iext
@@ -28,6 +29,8 @@ def int_x(x, t, Iext):
2829
bp.math.disable_x64()
2930

3031
def test_2d_decision_making_model(self):
32+
import matplotlib.pyplot as plt
33+
3134
bp.math.enable_x64()
3235
gamma = 0.641 # Saturation factor for gating variable
3336
tau = 0.06 # Synaptic time constant [sec]

brainpy/initialize/tests/test_decay_inits.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22
import unittest
33

4-
import matplotlib.pyplot as plt
54
import numpy as np
65

76
import brainpy as bp
@@ -10,7 +9,11 @@
109

1110

1211
# visualization
13-
def mat_visualize(matrix, cmap=plt.cm.get_cmap('coolwarm')):
12+
def mat_visualize(matrix, cmap=None):
13+
import matplotlib.pyplot as plt
14+
if cmap is None:
15+
cmap = plt.cm.get_cmap('coolwarm')
16+
plt.cm.get_cmap('coolwarm')
1417
im = plt.matshow(matrix, cmap=cmap)
1518
plt.colorbar(mappable=im, shrink=0.8, aspect=15)
1619
plt.show()
@@ -71,6 +74,8 @@ def test_dog_decay_init2(self):
7174
assert isinstance(weights, bp.math.ndarray)
7275

7376
def test_dog_decay3(self):
77+
import matplotlib.pyplot as plt
78+
7479
size = (10, 12)
7580
dog_init = bp.init.DOGDecay(sigmas=(1., 3.),
7681
max_ws=(10., 5.),

brainpy/inputs/tests/test_currents.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33

44
from unittest import TestCase
55

6-
import matplotlib.pyplot as plt
6+
77
import numpy as np
88

99
import brainpy as bp
1010

11+
plt = None
1112
block = False
1213

1314

1415
def show(current, duration, title=''):
16+
global plt
17+
if plt is None:
18+
import matplotlib.pyplot as plt
1519
ts = np.arange(0, duration, bp.math.get_dt())
1620
plt.plot(ts, current)
1721
plt.title(title)

brainpy/integrators/fde/tests/test_GL.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33

44
import unittest
5-
import matplotlib.pyplot as plt
5+
66
import brainpy as bp
77

8+
plt = None
9+
810

911
class TestGLShortMemory(unittest.TestCase):
1012
def test_lorenz(self):
13+
global plt
14+
if plt is None:
15+
import matplotlib.pyplot as plt
16+
1117
a, b, c = 10, 28, 8 / 3
1218

1319
def lorenz(x, y, z, t):

brainpy/integrators/ode/tests/test_ode_method_adaptive_rk.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
import unittest
44

5-
import matplotlib.pyplot as plt
65
import numpy as np
76

87
import brainpy.math as bm
98
from brainpy.integrators.ode import adaptive_rk
109

10+
plt = None
11+
12+
1113
sigma = 10
1214
beta = 8 / 3
1315
rho = 28
@@ -23,6 +25,10 @@ def f_lorenz(x, y, z, t):
2325

2426

2527
def run_integrator(method, show=False, tol=0.001, adaptive=True):
28+
global plt
29+
if plt is None:
30+
import matplotlib.pyplot as plt
31+
2632
f_integral = method(f_lorenz, adaptive=adaptive, tol=tol, show_code=True)
2733
x, y, z = bm.ones(1), bm.ones(1), bm.ones(1)
2834
dt = bm.ones(1) * 0.01

brainpy/integrators/ode/tests/test_ode_method_exp_euler.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# -*- coding: utf-8 -*-
22

33
import unittest
4-
import numpy as np
5-
import matplotlib.pyplot as plt
64
import pytest
75

86
import brainpy as bp
97
import brainpy.math as bm
108
from brainpy.integrators.ode.exponential import ExponentialEuler
119

10+
plt = None
11+
1212

1313
class TestExpnentialEuler(unittest.TestCase):
1414
def test_hh_model(self):
@@ -227,6 +227,10 @@ def dev(x, t):
227227

228228
class TestExpEulerAuto(unittest.TestCase):
229229
def test_hh_model(self):
230+
global plt
231+
if plt is None:
232+
import matplotlib.pyplot as plt
233+
230234
class HH(bp.dyn.NeuGroup):
231235
def __init__(self, size, ENa=55., EK=-90., EL=-65, C=1.0, gNa=35., gK=9.,
232236
gL=0.1, V_th=20., phi=5.0, name=None, method='exponential_euler'):

brainpy/integrators/ode/tests/test_ode_method_rk.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import unittest
44

5-
import matplotlib.pyplot as plt
65
import numpy as np
76

87
import brainpy.math as bm
98
from brainpy.integrators.ode import explicit_rk
9+
plt = None
1010

1111
sigma = 10
1212
beta = 8 / 3
@@ -23,6 +23,10 @@ def f_lorenz(x, y, z, t):
2323

2424

2525
def run_integrator(method, show=False):
26+
global plt
27+
if plt is None:
28+
import matplotlib.pyplot as plt
29+
2630
f_integral = bm.jit(method(f_lorenz, dt=dt), auto_infer=False)
2731
x, y, z = bm.ones(1), bm.ones(1), bm.ones(1)
2832

brainpy/integrators/sde/tests/test_sde_scalar.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import brainpy as bp
99
from brainpy.integrators import sde
1010

11+
plt = None
12+
1113
sigma = 10
1214
beta = 8 / 3
1315
rho = 28
@@ -42,17 +44,21 @@ def lorenz_system(method, **kwargs):
4244
mon1.append(x)
4345
mon2.append(y)
4446
mon3.append(z)
45-
mon1 = bp.math.array(mon1)
46-
mon2 = bp.math.array(mon2)
47-
mon3 = bp.math.array(mon3)
48-
49-
# fig = plt.figure()
50-
# ax = fig.gca(projection='3d')
51-
# plt.plot(mon1, mon2, mon3)
52-
# ax.set_xlabel('x')
53-
# ax.set_xlabel('y')
54-
# ax.set_xlabel('z')
55-
# plt.show()
47+
mon1 = bp.math.array(mon1).to_numpy()
48+
mon2 = bp.math.array(mon2).to_numpy()
49+
mon3 = bp.math.array(mon3).to_numpy()
50+
51+
global plt
52+
if plt is None:
53+
import matplotlib.pyplot as plt
54+
55+
fig = plt.figure()
56+
ax = fig.gca(projection='3d')
57+
plt.plot(mon1, mon2, mon3)
58+
ax.set_xlabel('x')
59+
ax.set_xlabel('y')
60+
ax.set_xlabel('z')
61+
plt.show()
5662

5763

5864
class TestScalarWienerIntegral(unittest.TestCase):

brainpy/integrators/tests/test_integ_runner.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
from unittest import TestCase
44

5-
import matplotlib.pyplot as plt
6-
75
import brainpy as bp
86

7+
plt = None
8+
99

1010
class TestIntegratorRunnerForODEs(TestCase):
1111
def test_ode(self):
12+
global plt
13+
if plt is None:
14+
import matplotlib.pyplot as plt
1215
sigma = 10
1316
beta = 8 / 3
1417
rho = 28

brainpy/nn/nodes/ANN/normalization.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import jax.numpy as jnp
77

88
import brainpy.math as bm
9-
import brainpy
109
from brainpy.initialize import ZeroInit, OneInit, Initializer
1110
from brainpy.nn.base import Node
1211

0 commit comments

Comments
 (0)