From 198ca86d6b9c25b58aed1d66346fb414a558de4e Mon Sep 17 00:00:00 2001 From: "Jeffrey Hokanson (Baldr)" Date: Tue, 14 Sep 2021 12:34:30 -0600 Subject: [PATCH] Removing depicrated numpy calls --- polyrat/aaa.py | 2 +- polyrat/basis.py | 2 +- polyrat/demos.py | 2 +- polyrat/index.py | 6 +++--- polyrat/lagrange.py | 4 ++-- polyrat/paaa.py | 8 ++++---- polyrat/rational_ratio.py | 14 +++++++------- polyrat/util.py | 12 ++++++------ tests/checkjac.py | 2 +- tests/test_aaa.py | 2 +- tests/test_arnoldi.py | 4 ++-- tests/test_lagrange.py | 2 +- tests/test_polynomial.py | 4 ++-- tests/test_rational.py | 2 +- 14 files changed, 33 insertions(+), 33 deletions(-) diff --git a/polyrat/aaa.py b/polyrat/aaa.py index 5966e15..a5f9c28 100644 --- a/polyrat/aaa.py +++ b/polyrat/aaa.py @@ -81,7 +81,7 @@ def aaa(x, y, degree = None, tol = None, verbose = True): mismatch = y - I = np.zeros(len(y), dtype = np.bool) # Index of x values used as barycentric nodes + I = np.zeros(len(y), dtype = bool) # Index of x values used as barycentric nodes if verbose: printer = IterationPrinter(it = '4d', res = '20.16e', cond = '8.3e') diff --git a/polyrat/basis.py b/polyrat/basis.py index eb40c8e..c966afb 100644 --- a/polyrat/basis.py +++ b/polyrat/basis.py @@ -45,7 +45,7 @@ def __init__(self, X, degree): self._indices = total_degree_index(self.dim, degree) self._mode = 'total' except (TypeError, ValueError): - self._degree = np.copy(degree).astype(np.int) + self._degree = np.copy(degree).astype(int) self._degree.flags.writeable = False assert len(self.degree) == self.dim, "maximum degree does not match the input dimension" self._indices = max_degree_index(self.degree) diff --git a/polyrat/demos.py b/polyrat/demos.py index 03ee5fd..6a88a2e 100644 --- a/polyrat/demos.py +++ b/polyrat/demos.py @@ -32,7 +32,7 @@ def penzl(X): A3 = np.array([[-1, 400], [-400,-1]]) A4 = -np.diag(np.arange(1, 1001)) - H = np.zeros(len(X), dtype = np.complex) + H = np.zeros(len(X), dtype = complex) for i, x in enumerate(X): z = x[0] diff --git a/polyrat/index.py b/polyrat/index.py index dc65398..a0fb98a 100644 --- a/polyrat/index.py +++ b/polyrat/index.py @@ -6,14 +6,14 @@ def fixed_degree_index(dim, degree): r""" Generate all combinations where sum == degree """ if dim == 1: - return np.array([[degree]]).astype(np.int) + return np.array([[degree]]).astype(int) else: idx = fixed_degree_index(dim - 1, degree) - idx = np.hstack([np.zeros((idx.shape[0],1), dtype = np.int), idx]) + idx = np.hstack([np.zeros((idx.shape[0],1), dtype = int), idx]) indices = [idx] for i in range(1, degree+1): idx = fixed_degree_index(dim - 1, degree - i) - idx = np.hstack([i*np.ones((idx.shape[0],1), dtype = np.int), idx]) + idx = np.hstack([i*np.ones((idx.shape[0],1), dtype = int), idx]) indices.append(idx) return np.vstack(indices) diff --git a/polyrat/lagrange.py b/polyrat/lagrange.py index c6653b0..85e6710 100644 --- a/polyrat/lagrange.py +++ b/polyrat/lagrange.py @@ -45,11 +45,11 @@ def lagrange_roots(nodes, weights, coef, deflation = True): # Build the RHS of the generalized eigenvalue problem - C0 = np.zeros((n+1, n+1), dtype=np.complex) + C0 = np.zeros((n+1, n+1), dtype=complex) C0[1:n+1,1:n+1] = np.diag(nodes) # LHS for generalized eigenvalue problem - C1 = np.eye(n+1, dtype=np.complex) + C1 = np.eye(n+1, dtype=complex) C1[0, 0] = 0 # scaling diff --git a/polyrat/paaa.py b/polyrat/paaa.py index 071c203..8427814 100644 --- a/polyrat/paaa.py +++ b/polyrat/paaa.py @@ -48,7 +48,7 @@ def paaa(X, y, verbose = True, maxiter = 100, tol = None): d = X.shape[1] r = np.zeros(y.shape) - degree = np.zeros(d, dtype = np.int) + degree = np.zeros(d, dtype = int) if verbose: @@ -56,7 +56,7 @@ def paaa(X, y, verbose = True, maxiter = 100, tol = None): printer.print_header(it = 'iter', degree = 'degree', norm = 'norm mismatch', cond = 'cond #') printer.print_iter(norm = np.linalg.norm(y)) # indices of points where we interpolate - I = np.zeros(y.shape[0], dtype = np.bool) + I = np.zeros(y.shape[0], dtype = bool) mismatch = np.copy(y) @@ -73,7 +73,7 @@ def paaa(X, y, verbose = True, maxiter = 100, tol = None): # determine points in tensor-product barycentric basis basis = [np.array(list(set(X[I,i]))).reshape(-1) for i in range(d)] - degree = np.array([len(b)-1 for b in basis], dtype = np.int) + degree = np.array([len(b)-1 for b in basis], dtype = int) # With this algorithm we need to "complete the square" # by adding all terms of the form @@ -140,7 +140,7 @@ def fit(self, X, y): self.X = np.copy(X) self.y = np.copy(y) self._I, self._b, self._basis, self._order = paaa(X, y, verbose = self.verbose, maxiter = self.maxiter) - self.degree = np.array([len(bi)-1 for bi in self._basis], dtype = np.int) + self.degree = np.array([len(bi)-1 for bi in self._basis], dtype = int) def __call__(self, X): diff --git a/polyrat/rational_ratio.py b/polyrat/rational_ratio.py index 226b86a..6735e47 100644 --- a/polyrat/rational_ratio.py +++ b/polyrat/rational_ratio.py @@ -51,7 +51,7 @@ def _rational_jacobian_complex(x, P, Q): np.multiply((1./Qb)[:,None], P), np.multiply(-(Pa/Qb**2)[:,None], Q), ]) - JRI = np.zeros((J.shape[0]*2, J.shape[1]*2), dtype = np.float) + JRI = np.zeros((J.shape[0]*2, J.shape[1]*2), dtype = float) JRI[0::2,0::2] = J.real JRI[1::2,1::2] = J.real JRI[0::2,1::2] = -J.imag @@ -69,7 +69,7 @@ def _rational_ratio_optimize_pin_2norm_real(y, P, Q, a0, b0, **kwargs): x0 = np.hstack([a0, b0[:k], b0[k+1:]]) xfun = lambda x: np.hstack([x[:m+k], b0[k], x[m+k:]]) - mask = np.ones(m+n, dtype = np.bool) + mask = np.ones(m+n, dtype = bool) mask[m+k] = 0 res = lambda x: _rational_residual_real(xfun(x), P, Q, y) jac = lambda x: _rational_jacobian_real(xfun(x), P, Q)[:,mask] @@ -85,7 +85,7 @@ def _rational_ratio_optimize_pin_2norm_complex(y, P, Q, a0, b0, **kwargs): x0 = np.hstack([a0, b0[:k], b0[k+1:]]) xfun = lambda x: np.hstack([x[:2*(m+k)], b0[k].real, b0[k].imag, x[2*(m+k):]]) - mask = np.ones(2*(m+n), dtype = np.bool) + mask = np.ones(2*(m+n), dtype = bool) mask[2*(m+k):2*(m+k)+2] = 0 res = lambda x: _rational_residual_complex(xfun(x), P, Q, y) jac = lambda x: _rational_jacobian_complex(xfun(x), P, Q)[:,mask] @@ -197,10 +197,10 @@ def rational_ratio_optimize(y, P, Q, a0, b0, norm = 2, **kwargs): if not isreal: - x0 = x0.astype(np.complex) - P = P.astype(np.complex) - Q = Q.astype(np.complex) - y = y.astype(np.complex) + x0 = x0.astype(complex) + P = P.astype(complex) + Q = Q.astype(complex) + y = y.astype(complex) if isreal and norm == 2: return _rational_ratio_optimize_pin_2norm_real(y, P, Q, a0, b0, **kwargs) diff --git a/polyrat/util.py b/polyrat/util.py index c086f27..3440d51 100644 --- a/polyrat/util.py +++ b/polyrat/util.py @@ -29,9 +29,9 @@ def _zeros(size, *args): r""" allocate a zeros matrix of the given size matching the type of the arguments """ if all([np.isrealobj(a) for a in args]): - return np.zeros(size, dtype = np.float) + return np.zeros(size, dtype = float) else: - return np.zeros(size, dtype = np.complex) + return np.zeros(size, dtype = complex) def linearized_ratfit_operator_dense(P, Q, Y, weight = None): r""" Dense analog of LinearizedRatfitOperator @@ -207,9 +207,9 @@ def _matmat(self, X): np.iscomplexobj(self.Q), np.iscomplexobj(self.Y), np.iscomplexobj(X)]): - Z = np.zeros((self.shape[0], X.shape[1]), dtype = np.complex) + Z = np.zeros((self.shape[0], X.shape[1]), dtype = complex) else: - Z = np.zeros((self.shape[0], X.shape[1]), dtype = np.float) + Z = np.zeros((self.shape[0], X.shape[1]), dtype = float) M = self.Y.shape[0] m = self.P.shape[1] @@ -229,9 +229,9 @@ def _rmatmat(self, X): np.iscomplexobj(self.Q), np.iscomplexobj(self.Y), np.iscomplexobj(X)]): - Z = np.zeros((self.shape[1], X.shape[1]), dtype = np.complex) + Z = np.zeros((self.shape[1], X.shape[1]), dtype = complex) else: - Z = np.zeros((self.shape[1], X.shape[1]), dtype = np.float) + Z = np.zeros((self.shape[1], X.shape[1]), dtype = float) M = self.Y.shape[0] diff --git a/tests/checkjac.py b/tests/checkjac.py index cc5b5fe..3345443 100644 --- a/tests/checkjac.py +++ b/tests/checkjac.py @@ -10,7 +10,7 @@ def check_jacobian(x, residual, jacobian, h = 2e-7, relative = False): print("Jacobian condition number", np.linalg.cond(J)) for i in range(n): - ei = np.zeros(x.shape, dtype = np.float) + ei = np.zeros(x.shape, dtype = float) ei[i]= 1. x1 = x + ei * h diff --git a/tests/test_aaa.py b/tests/test_aaa.py index a9b8556..7b622b9 100644 --- a/tests/test_aaa.py +++ b/tests/test_aaa.py @@ -31,7 +31,7 @@ def test_eval_aaa(): xeval = np.linspace(-1,1, 2*M).reshape(-1,1) - I = np.zeros(M, dtype = np.bool) + I = np.zeros(M, dtype = bool) I[0] = 1 I[5] = 1 I[10] = 1 diff --git a/tests/test_arnoldi.py b/tests/test_arnoldi.py index 8a4a455..a60c6ee 100644 --- a/tests/test_arnoldi.py +++ b/tests/test_arnoldi.py @@ -10,14 +10,14 @@ def test_arnoldi_roots(n): true_roots = np.arange(1, n+1) def wilkinson(x): - value = np.zeros(x.shape, dtype = np.complex) + value = np.zeros(x.shape, dtype = complex) for i, xi in enumerate(x): value[i] = np.prod(xi - true_roots) return value # It is important that we sample at the roots to avoid the large # values the Wilkinson polynomial takes away from these points. - X = np.arange(0, n+1, step = 0.1, dtype = np.float).reshape(-1,1) + X = np.arange(0, n+1, step = 0.1, dtype = float).reshape(-1,1) y = wilkinson(X).flatten() arn = PolynomialApproximation(n, Basis = ArnoldiPolynomialBasis) diff --git a/tests/test_lagrange.py b/tests/test_lagrange.py index da72d89..0737bf7 100644 --- a/tests/test_lagrange.py +++ b/tests/test_lagrange.py @@ -18,7 +18,7 @@ def test_wilkinson(n, ang, deflate): true_roots = ang* np.arange(1, n+1) def wilkinson(x): - value = np.zeros(x.shape, dtype = np.complex) + value = np.zeros(x.shape, dtype = complex) for i, xi in enumerate(x): value[i] = np.prod(xi - true_roots) return value diff --git a/tests/test_polynomial.py b/tests/test_polynomial.py index 4686816..0de890a 100644 --- a/tests/test_polynomial.py +++ b/tests/test_polynomial.py @@ -23,14 +23,14 @@ def test_wilkinson_roots(Basis, n): true_roots = np.arange(1, n+1) def wilkinson(x): - value = np.zeros(x.shape, dtype = np.complex) + value = np.zeros(x.shape, dtype = complex) for i, xi in enumerate(x): value[i] = np.prod(xi - true_roots) return value # It is important that we sample at the roots to avoid the large # values the Wilkinson polynomial takes away from these points. - X = np.arange(0, n+1, step = 0.1, dtype = np.float).reshape(-1,1) + X = np.arange(0, n+1, step = 0.1, dtype = float).reshape(-1,1) y = wilkinson(X).flatten() poly = PolynomialApproximation(n, Basis = Basis) poly.fit(X, y) diff --git a/tests/test_rational.py b/tests/test_rational.py index d383586..056ae80 100644 --- a/tests/test_rational.py +++ b/tests/test_rational.py @@ -41,7 +41,7 @@ def test_rational_pole_residue(): poles, residues = rat.pole_residue() xhat = X[0:1] yhat = rat(xhat) - yhat2 = np.zeros(yhat.shape, dtype = np.complex) + yhat2 = np.zeros(yhat.shape, dtype = complex) for lam, R in zip(poles, residues): yhat2 += R/(xhat.flatten() - lam)