Skip to content

Commit

Permalink
Removing depicrated numpy calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Hokanson (Baldr) committed Sep 14, 2021
1 parent 6128816 commit 198ca86
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion polyrat/aaa.py
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion polyrat/basis.py
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion polyrat/demos.py
Expand Up @@ -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]

Expand Down
6 changes: 3 additions & 3 deletions polyrat/index.py
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions polyrat/lagrange.py
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions polyrat/paaa.py
Expand Up @@ -48,15 +48,15 @@ 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:
printer = IterationPrinter(it = '4d', degree = f'{2+3*d:d}s', norm = '20.10e', cond = '10.2e')
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)
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down
14 changes: 7 additions & 7 deletions polyrat/rational_ratio.py
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions polyrat/util.py
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/checkjac.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_aaa.py
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_arnoldi.py
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lagrange.py
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_polynomial.py
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_rational.py
Expand Up @@ -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)

Expand Down

0 comments on commit 198ca86

Please sign in to comment.