Skip to content

Commit a1d7884

Browse files
committed
Remove deprecated sparse .H and .A attributes, which are removed in scipy 1.14
1 parent f5c07ab commit a1d7884

9 files changed

Lines changed: 25 additions & 25 deletions

File tree

dedalus/core/coords.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def forward_vector_intertwiner(self, subaxis, group):
138138
else:
139139
factors.append(np.identity(cs.dim))
140140
start_axis += cs.dim
141-
return sparse_block_diag(factors).A
141+
return sparse_block_diag(factors).toarray()
142142

143143
def backward_vector_intertwiner(self, subaxis, group):
144144
factors = []
@@ -149,7 +149,7 @@ def backward_vector_intertwiner(self, subaxis, group):
149149
else:
150150
factors.append(np.identity(cs.dim))
151151
start_axis += cs.dim
152-
return sparse_block_diag(factors).A
152+
return sparse_block_diag(factors).toarray()
153153

154154
@CachedAttribute
155155
def default_nonconst_groups(self):

dedalus/core/solvers.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ def print_subproblem_ranks(self, subproblems=None, target=0):
172172
for i, sp in enumerate(subproblems):
173173
if not hasattr(sp, 'L_min'):
174174
continue
175-
L = sp.L_min.A
176-
M = sp.M_min.A
175+
L = sp.L_min.toarray()
176+
M = sp.M_min.toarray()
177177
A = L + target * M
178178
print(f"MPI rank: {self.dist.comm.rank}, subproblem: {i}, group: {sp.group}, matrix rank: {np.linalg.matrix_rank(A)}/{A.shape[0]}, cond: {np.linalg.cond(A):.1e}")
179179

@@ -205,15 +205,15 @@ def solve_dense(self, subproblem, rebuild_matrices=False, left=False, normalize_
205205
if rebuild_matrices or not hasattr(sp, 'L_min'):
206206
self.build_matrices([sp], ['M', 'L'])
207207
# Solve as dense general eigenvalue problem
208-
A = sp.L_min.A
209-
B = - sp.M_min.A
208+
A = sp.L_min.toarray()
209+
B = - sp.M_min.toarray()
210210
eig_output = scipy.linalg.eig(A, b=B, left=left, **kw)
211211
# Unpack output
212212
if left:
213213
self.eigenvalues, pre_left_evecs, pre_right_evecs = eig_output
214214
self.right_eigenvectors = self.eigenvectors = sp.pre_right @ pre_right_evecs
215-
self.left_eigenvectors = sp.pre_left.H @ pre_left_evecs
216-
self.modified_left_eigenvectors = (sp.M_min @ sp.pre_right_pinv).H @ pre_left_evecs
215+
self.left_eigenvectors = sp.pre_left.conj().toarray() @ pre_left_evecs
216+
self.modified_left_eigenvectors = (sp.M_min @ sp.pre_right_pinv).conj().toarray() @ pre_left_evecs
217217
if normalize_left:
218218
norms = np.diag(pre_left_evecs.T.conj() @ sp.M_min @ pre_right_evecs)
219219
self.left_eigenvectors /= np.conj(norms)
@@ -270,8 +270,8 @@ def solve_sparse(self, subproblem, N, target, rebuild_matrices=False, left=False
270270
# Note: this definition of "left eigenvectors" is consistent with the documentation for scipy.linalg.eig
271271
self.eigenvalues, pre_right_evecs, self.left_eigenvalues, pre_left_evecs = eig_output
272272
self.right_eigenvectors = self.eigenvectors = sp.pre_right @ pre_right_evecs
273-
self.left_eigenvectors = sp.pre_left.H @ pre_left_evecs
274-
self.modified_left_eigenvectors = (sp.M_min @ sp.pre_right_pinv).H @ pre_left_evecs
273+
self.left_eigenvectors = sp.pre_left.conj().toarray() @ pre_left_evecs
274+
self.modified_left_eigenvectors = (sp.M_min @ sp.pre_right_pinv).conj().toarray() @ pre_left_evecs
275275
# Check that eigenvalues match
276276
if not np.allclose(self.eigenvalues, np.conjugate(self.left_eigenvalues)):
277277
if raise_on_mismatch:
@@ -363,7 +363,7 @@ def print_subproblem_ranks(self, subproblems=None):
363363
for i, sp in enumerate(subproblems):
364364
if not hasattr(sp, 'L_min'):
365365
continue
366-
L = sp.L_min.A
366+
L = sp.L_min.toarray()
367367
print(f"MPI rank: {self.dist.comm.rank}, subproblem: {i}, group: {sp.group}, matrix rank: {np.linalg.matrix_rank(L)}/{L.shape[0]}, cond: {np.linalg.cond(L):.1e}")
368368

369369
def solve(self, subproblems=None, rebuild_matrices=False):
@@ -464,7 +464,7 @@ def print_subproblem_ranks(self, subproblems=None):
464464
for i, sp in enumerate(subproblems):
465465
if not hasattr(sp, 'dF_min'):
466466
continue
467-
dF = sp.dF_min.A
467+
dF = sp.dF_min.toarray()
468468
print(f"MPI rank: {self.dist.comm.rank}, subproblem: {i}, group: {sp.group}, matrix rank: {np.linalg.matrix_rank(dF)}/{dF.shape[0]}, cond: {np.linalg.cond(dF):.1e}")
469469

470470
def newton_iteration(self, damping=1):
@@ -739,7 +739,7 @@ def print_subproblem_ranks(self, subproblems=None, dt=1):
739739
for i, sp in enumerate(subproblems):
740740
M = sp.M_min
741741
L = sp.L_min
742-
A = (M + dt*L).A
742+
A = (M + dt*L).toarray()
743743
print(f"MPI rank: {self.dist.comm.rank}, subproblem: {i}, group: {sp.group}, matrix rank: {np.linalg.matrix_rank(A)}/{A.shape[0]}, cond: {np.linalg.cond(A):.1e}")
744744

745745
def evaluate_handlers_now(self, dt, handlers=None):

dedalus/libraries/dedalus_sphere/clenshaw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def jacobi_recursion(N, a, b, X):
3232
"""
3333
# Jacobi matrix
3434
J = jacobi_matrix(N, a, b)
35-
JA = J.A
35+
JA = J.toarray()
3636
# Identity element
3737
if np.isscalar(X):
3838
I = 1

dedalus/libraries/dedalus_sphere/jacobi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def grid_guess(n,a,b,dtype='longdouble',quick=False):
132132
quick = True
133133

134134
if n == 1:
135-
return operator('Z')(n,a,b).A[0]
135+
return operator('Z')(n,a,b).toarray()[0]
136136

137137
if quick:
138138
return np.cos(np.pi*(np.arange(4*n-1,2,-4,dtype=dtype)+2*a)/(4*n+2*(a+b+1)))

dedalus/libraries/dedalus_sphere/tests/test_jacobi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_Ap_Bp_commutation(N, a, b):
8787
Bp00 = jacobi128.operator('B+', N, a, b)
8888
Ap01 = jacobi128.operator('A+', N, a, b+1)
8989
path2 = Ap01 @ Bp00
90-
assert np.allclose(path1.A, path2.A)
90+
assert np.allclose(path1.toarray(), path2.toarray())
9191

9292

9393
@pytest.mark.parametrize('N', N_range)
@@ -105,5 +105,5 @@ def test_App_Bpp_commutation(N, a, b):
105105
Ap02 = jacobi128.operator('A+', N, a, b+2)
106106
Ap12 = jacobi128.operator('A+', N, a+1, b+2)
107107
path2 = Ap12 @ Ap02 @ Bp01 @ Bp00
108-
assert np.allclose(path1.A, path2.A)
108+
assert np.allclose(path1.toarray(), path2.toarray())
109109

dedalus/libraries/matsolvers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def __init__(self, matrix, solver=None):
137137
if self.trans == "T":
138138
matrix = matrix.T
139139
elif self.trans == "H":
140-
matrix = matrix.H
140+
matrix = matrix.conj().toarray()
141141
self.LU = spla.splu(matrix.tocsc(),
142142
permc_spec=self.permc_spec,
143143
diag_pivot_thresh=self.diag_pivot_thresh,
@@ -235,7 +235,7 @@ class DenseInverse(DenseSolver):
235235
"""Dense inversion solve."""
236236

237237
def __init__(self, matrix, solver=None):
238-
self.matrix_inverse = sla.inv(matrix.A)
238+
self.matrix_inverse = sla.inv(matrix.toarray())
239239

240240
def solve(self, vector):
241241
return self.matrix_inverse @ vector
@@ -276,7 +276,7 @@ class ScipyDenseLU(DenseSolver):
276276
"""Scipy dense LU factorized solve."""
277277

278278
def __init__(self, matrix, solver=None):
279-
self.LU = sla.lu_factor(matrix.A, check_finite=False)
279+
self.LU = sla.lu_factor(matrix.toarray(), check_finite=False)
280280

281281
def solve(self, vector):
282282
return sla.lu_solve(self.LU, vector, check_finite=False)
@@ -296,9 +296,9 @@ def __init__(self, matrix, subproblem, matsolver):
296296
self.V = V = np.zeros((2*R, matrix.shape[1]), dtype=matrix.dtype)
297297
# Remove top border, leaving upper left subblock
298298
U[:R, :R] = np.identity(R)
299-
V[:R, R:] = matrix[:R, R:].A
299+
V[:R, R:] = matrix[:R, R:].toarray()
300300
# Remove right border, leaving upper right and lower right subblocks
301-
U[R:-R, R:] = matrix[R:-R, -R:].A
301+
U[R:-R, R:] = matrix[R:-R, -R:].toarray()
302302
V[-R:, -R:] = np.identity(R)
303303
self.A = matrix - sp.csr_matrix(U) @ sp.csr_matrix(V)
304304
# Solve A using specified matsolver

dedalus/tests/test_nlbvp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def error(perts):
324324
R = -φcen / (n+1)**(3/2)
325325
print(solver.iteration, φcen, R, err)
326326
dH = solver.subproblems[0].dH_min
327-
print('%.2e' %np.linalg.cond(dH.A))
327+
print('%.2e' %np.linalg.cond(dH.toarray()))
328328
if err > tolerance:
329329
raise ValueError("Did not converge")
330330
# Compare to reference solutions from Boyd

dedalus/tools/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ def matvec(x):
433433
# Build sparse linear operator representing (A^H - conj(σ)B^H)^I B^H = C^-H B^H = left_D
434434
# Note: left_D is not equal to D^H
435435
def matvec_left(x):
436-
return solver.solve_H(B.H.dot(x))
436+
return solver.solve_H(B.conj().toarray().dot(x))
437437
left_D = spla.LinearOperator(dtype=A.dtype, shape=A.shape, matvec=matvec_left)
438438
# Solve using scipy sparse algorithm
439439
left_evals, left_evecs = spla.eigs(left_D, k=N, which='LM', sigma=None, **kw)

dedalus/tools/clenshaw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def jacobi_recursion(N, a, b, X):
7979
"""
8080
# Jacobi matrix
8181
J = jacobi.jacobi_matrix(N, a, b)
82-
JA = J.A
82+
JA = J.toarray()
8383
# Identity element
8484
if np.isscalar(X):
8585
I = 1

0 commit comments

Comments
 (0)