Skip to content

Commit 7a5a37e

Browse files
committed
Updated np.float to float throughout to remove deprecation warning
1 parent 858793e commit 7a5a37e

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

dfols/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"

dfols/solver.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ def solve_main(objfun, x0, args, xl, xu, npt, rhobeg, rhoend, maxfun, nruns_so_f
852852

853853
def solve(objfun, x0, args=(), bounds=None, npt=None, rhobeg=None, rhoend=1e-8, maxfun=None, nsamples=None, user_params=None,
854854
objfun_has_noise=False, scaling_within_bounds=False, do_logging=True, print_progress=False):
855-
x0 = x0.astype(np.float)
855+
x0 = x0.astype(float)
856856
n = len(x0)
857857

858858
# Set missing inputs (if not specified) to some sensible defaults
@@ -861,8 +861,8 @@ def solve(objfun, x0, args=(), bounds=None, npt=None, rhobeg=None, rhoend=1e-8,
861861
xu = None
862862
else:
863863
assert len(bounds) == 2, "bounds must be a 2-tuple of (lower, upper), where both are arrays of size(x0)"
864-
xl = bounds[0].astype(np.float) if bounds[0] is not None else None
865-
xu = bounds[1].astype(np.float) if bounds[1] is not None else None
864+
xl = bounds[0].astype(float) if bounds[0] is not None else None
865+
xu = bounds[1].astype(float) if bounds[1] is not None else None
866866

867867
if (xl is None or xu is None) and scaling_within_bounds:
868868
scaling_within_bounds = False

dfols/tests/test_hessian.py

Lines changed: 12 additions & 12 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,23 +151,23 @@ 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))

dfols/tests/test_util.py

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

0 commit comments

Comments
 (0)