Skip to content

Commit 4995169

Browse files
committed
Updated tests (np.all to np.allclose and remove depcrecation warning)
1 parent 055d0c1 commit 4995169

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

pybobyqa/tests/test_trust_region.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def runTest(self):
8989
# self.assertAlmostEqual(est_min, true_min, 'Wrong min value')
9090
s_cauchy, red_cauchy, crvmin_cauchy = cauchy_pt(g, H, Delta)
9191
self.assertTrue(est_min <= red_cauchy, 'Cauchy reduction not achieved')
92-
self.assertTrue(np.all(gnew == g + H.dot(d)), 'Wrong gnew')
92+
self.assertTrue(np.allclose(gnew, g + H.dot(d)), 'Wrong gnew')
9393
# print(crvmin)
9494
self.assertAlmostEqual(crvmin, 1.2, 'Wrong crvmin')
9595

@@ -112,7 +112,7 @@ def runTest(self):
112112
# self.assertAlmostEqual(est_min, true_min, 'Wrong min value')
113113
s_cauchy, red_cauchy, crvmin_cauchy = cauchy_pt(g, H, Delta)
114114
self.assertTrue(est_min <= red_cauchy, 'Cauchy reduction not achieved')
115-
self.assertTrue(np.all(gnew == g + H.dot(d)), 'Wrong gnew')
115+
self.assertTrue(np.allclose(gnew, g + H.dot(d)), 'Wrong gnew')
116116
self.assertAlmostEqual(crvmin, 0.0, 'Wrong crvmin')
117117

118118

@@ -134,7 +134,7 @@ def runTest(self):
134134
# self.assertAlmostEqual(est_min, true_min, 'Wrong min value')
135135
s_cauchy, red_cauchy, crvmin_cauchy = cauchy_pt(g, H, Delta)
136136
self.assertTrue(est_min <= red_cauchy, 'Cauchy reduction not achieved')
137-
self.assertTrue(np.all(gnew == g + H.dot(d)), 'Wrong gnew')
137+
self.assertTrue(np.allclose(gnew, g + H.dot(d)), 'Wrong gnew')
138138
self.assertAlmostEqual(crvmin, 0.0, 'Wrong crvmin')
139139

140140

@@ -156,7 +156,7 @@ def runTest(self):
156156
# self.assertAlmostEqual(est_min, true_min, 'Wrong min value')
157157
s_cauchy, red_cauchy, crvmin_cauchy = cauchy_pt(g, H, Delta)
158158
self.assertTrue(est_min <= red_cauchy, 'Cauchy reduction not achieved')
159-
self.assertTrue(np.all(gnew == g + H.dot(d)), 'Wrong gnew')
159+
self.assertTrue(np.allclose(gnew, g + H.dot(d)), 'Wrong gnew')
160160
self.assertAlmostEqual(crvmin, 0.0, 'Wrong crvmin')
161161
# self.assertAlmostEqual(crvmin, crvmin_cauchy, 'Wrong crvmin')
162162

@@ -179,7 +179,7 @@ def runTest(self):
179179
# self.assertAlmostEqual(est_min, true_min, 'Wrong min value')
180180
s_cauchy, red_cauchy, crvmin_cauchy = cauchy_pt(g, H, Delta)
181181
self.assertTrue(est_min <= red_cauchy, 'Cauchy reduction not achieved')
182-
self.assertTrue(np.all(gnew == g + H.dot(d)), 'Wrong gnew')
182+
self.assertTrue(np.allclose(gnew, g + H.dot(d)), 'Wrong gnew')
183183
self.assertAlmostEqual(crvmin, 0.0, 'Wrong crvmin')
184184

185185

@@ -203,7 +203,7 @@ def runTest(self):
203203
# print(s_cauchy)
204204
# print(d)
205205
self.assertTrue(est_min <= red_cauchy, 'Cauchy reduction not achieved')
206-
self.assertTrue(np.all(gnew == g + H.dot(d)), 'Wrong gnew')
206+
self.assertTrue(np.allclose(gnew, g + H.dot(d)), 'Wrong gnew')
207207
# print(crvmin)
208208
self.assertAlmostEqual(crvmin, -1.0, 'Wrong crvmin')
209209

pybobyqa/tests/test_util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ def runTest(self):
5252
class TestModelValue(unittest.TestCase):
5353
def runTest(self):
5454
n = 5
55-
A = np.arange(n ** 2, dtype=np.float).reshape((n, n))
55+
A = np.arange(n ** 2, dtype=float).reshape((n, n))
5656
H = np.sin(A + A.T) # force symmetric
57-
vec = np.exp(np.arange(n, dtype=np.float))
58-
g = np.cos(3*np.arange(n, dtype=np.float) - 2.0)
57+
vec = np.exp(np.arange(n, dtype=float))
58+
g = np.cos(3*np.arange(n, dtype=float) - 2.0)
5959
mval = np.dot(g, vec) + 0.5 * np.dot(vec, np.dot(H, vec))
6060
self.assertAlmostEqual(mval, model_value(g, H, vec), msg='Wrong value')
6161

0 commit comments

Comments
 (0)