Skip to content

Commit 7a6fc25

Browse files
committed
Changed np.float to float (to remove deprecation warning)
1 parent b8e2dc0 commit 7a6fc25

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

pybobyqa/hessian.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Hessian(object):
3939
def __init__(self, n, vals=None):
4040
self.n = n
4141
if vals is None:
42-
self.hq = np.zeros((n * (n + 1) // 2,), dtype=np.float)
42+
self.hq = np.zeros((n * (n + 1) // 2,), dtype=float)
4343
else:
4444
assert isinstance(vals, np.ndarray), "Can only set Hessian from NumPy array"
4545
assert len(vals.shape) in [1, 2], "Can only set Hessian from vector or matrix"

pybobyqa/solver.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -667,9 +667,9 @@ def solve(objfun, x0, args=(), bounds=None, npt=None, rhobeg=None, rhoend=1e-8,
667667
objfun_has_noise=False, seek_global_minimum=False, scaling_within_bounds=False, do_logging=True, print_progress=False):
668668
n = len(x0)
669669
if type(x0) == list:
670-
x0 = np.array(x0, dtype=np.float)
670+
x0 = np.array(x0, dtype=float)
671671
else:
672-
x0 = x0.astype(np.float)
672+
x0 = x0.astype(float)
673673

674674
# Set missing inputs (if not specified) to some sensible defaults
675675
if bounds is None:
@@ -680,14 +680,14 @@ def solve(objfun, x0, args=(), bounds=None, npt=None, rhobeg=None, rhoend=1e-8,
680680
assert len(bounds) == 2, "bounds must be a 2-tuple of (lower, upper), where both are arrays of size(x0)"
681681
xl = bounds[0]
682682
if type(xl) == list:
683-
xl = np.array(xl, dtype=np.float) if xl is not None else None
683+
xl = np.array(xl, dtype=float) if xl is not None else None
684684
else:
685-
xl = xl.astype(np.float) if xl is not None else None
685+
xl = xl.astype(float) if xl is not None else None
686686
xu = bounds[1]
687687
if type(xu) == list:
688-
xu = np.array(xu, dtype=np.float) if xu is not None else None
688+
xu = np.array(xu, dtype=float) if xu is not None else None
689689
else:
690-
xu = xu.astype(np.float) if xu is not None else None
690+
xu = xu.astype(float) if xu is not None else None
691691

692692
if (xl is None or xu is None) and scaling_within_bounds:
693693
scaling_within_bounds = False

pybobyqa/tests/test_hessian.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class TestInitFromVector(unittest.TestCase):
4848
def runTest(self):
4949
n = 5
5050
nvals = n*(n+1)//2
51-
x = np.arange(nvals, dtype=np.float)
51+
x = np.arange(nvals, dtype=float)
5252
hess = Hessian(n, vals=x)
5353
self.assertEqual(hess.shape(), (nvals,), 'Wrong shape for initialisation')
5454
self.assertEqual(hess.dim(), n, 'Wrong dimension')
@@ -60,7 +60,7 @@ class TestInitFromMatrix(unittest.TestCase):
6060
def runTest(self):
6161
n = 3
6262
nvals = n*(n+1)//2
63-
A = np.arange(n**2, dtype=np.float).reshape((n,n))
63+
A = np.arange(n**2, dtype=float).reshape((n,n))
6464
hess = Hessian(n, vals=A+A.T) # force symmetric
6565
self.assertEqual(hess.shape(), (nvals,), 'Wrong shape for initialisation')
6666
self.assertEqual(hess.dim(), n, 'Wrong dimension')
@@ -72,7 +72,7 @@ def runTest(self):
7272
class TestToFull(unittest.TestCase):
7373
def runTest(self):
7474
n = 7
75-
A = np.arange(n ** 2, dtype=np.float).reshape((n, n))
75+
A = np.arange(n ** 2, dtype=float).reshape((n, n))
7676
H = A + A.T # force symmetric
7777
hess = Hessian(n, vals=H)
7878
self.assertTrue(np.all(hess.as_full() == H), 'Wrong values')
@@ -81,7 +81,7 @@ def runTest(self):
8181
class TestGetElementGood(unittest.TestCase):
8282
def runTest(self):
8383
n = 3
84-
A = np.arange(n ** 2, dtype=np.float).reshape((n, n))
84+
A = np.arange(n ** 2, dtype=float).reshape((n, n))
8585
H = A + A.T # force symmetric
8686
hess = Hessian(n, vals=H)
8787
for i in range(n):
@@ -93,7 +93,7 @@ def runTest(self):
9393
class TestGetElementBad(unittest.TestCase):
9494
def runTest(self):
9595
n = 4
96-
A = np.arange(n ** 2, dtype=np.float).reshape((n, n))
96+
A = np.arange(n ** 2, dtype=float).reshape((n, n))
9797
H = A + A.T # force symmetric
9898
hess = Hessian(n, vals=H)
9999
# When testing for assertion errors, need lambda to stop assertion from actually happening
@@ -114,7 +114,7 @@ def runTest(self):
114114
class TestSetElementGood(unittest.TestCase):
115115
def runTest(self):
116116
n = 3
117-
A = np.arange(n ** 2, dtype=np.float).reshape((n, n))
117+
A = np.arange(n ** 2, dtype=float).reshape((n, n))
118118
H = A + A.T # force symmetric
119119
hess = Hessian(n, vals=H)
120120
H2 = np.sin(H)
@@ -130,7 +130,7 @@ def runTest(self):
130130
class TestSetElementBad(unittest.TestCase):
131131
def runTest(self):
132132
n = 5
133-
A = np.arange(n ** 2, dtype=np.float).reshape((n, n))
133+
A = np.arange(n ** 2, dtype=float).reshape((n, n))
134134
H = A + A.T # force symmetric
135135
hess = Hessian(n, vals=H)
136136
# When testing for assertion errors, need lambda to stop assertion from actually happening
@@ -151,32 +151,32 @@ def runTest(self):
151151
class TestMultGood(unittest.TestCase):
152152
def runTest(self):
153153
n = 5
154-
A = np.arange(n ** 2, dtype=np.float).reshape((n, n))
154+
A = np.arange(n ** 2, dtype=float).reshape((n, n))
155155
H = np.sin(A + A.T) # force symmetric
156156
hess = Hessian(n, vals=H)
157-
vec = np.exp(np.arange(n, dtype=np.float))
157+
vec = np.exp(np.arange(n, dtype=float))
158158
hs = np.dot(H, vec)
159159
self.assertTrue(array_compare(hess*vec, hs, thresh=1e-12), 'Wrong values')
160160

161161

162162
class TestMultBad(unittest.TestCase):
163163
def runTest(self):
164164
n = 5
165-
A = np.arange(n ** 2, dtype=np.float).reshape((n, n))
165+
A = np.arange(n ** 2, dtype=float).reshape((n, n))
166166
H = A + A.T # force symmetric
167167
hess = Hessian(n, vals=H)
168168
# When testing for assertion errors, need lambda to stop assertion from actually happening
169169
self.assertRaises(AssertionError, lambda: hess * 1.0)
170170
self.assertRaises(AssertionError, lambda: hess * None)
171171
self.assertRaises(AssertionError, lambda: hess * [float(i) for i in range(n)])
172-
self.assertRaises(AssertionError, lambda: hess * np.arange(n-1, dtype=np.float))
173-
self.assertRaises(AssertionError, lambda: hess * np.arange(n+1, dtype=np.float))
172+
self.assertRaises(AssertionError, lambda: hess * np.arange(n-1, dtype=float))
173+
self.assertRaises(AssertionError, lambda: hess * np.arange(n+1, dtype=float))
174174

175175

176176
class TestNeg(unittest.TestCase):
177177
def runTest(self):
178178
n = 5
179-
A = np.arange(n ** 2, dtype=np.float).reshape((n, n))
179+
A = np.arange(n ** 2, dtype=float).reshape((n, n))
180180
H = A + A.T # force symmetric
181181
hess = Hessian(n, vals=H)
182182
neghess = -hess

pybobyqa/tests/test_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def rosenbrock(x):
4545

4646
def objfun(x):
4747
# An arbitrary-dimension objective function
48-
return sin(np.dot(x, np.arange(1,len(x)+1,dtype=np.float))) # f(x1,...,xn) = sin(x1 + 2*x2 + ... + n*xn)
48+
return sin(np.dot(x, np.arange(1,len(x)+1,dtype=float))) # f(x1,...,xn) = sin(x1 + 2*x2 + ... + n*xn)
4949

5050

5151
class TestAddValues(unittest.TestCase):

0 commit comments

Comments
 (0)