Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def solver(mesh):
matrix, rhs = pyfvm.discretize_linear(Convection(), mesh)
ml = pyamg.smoothed_aggregation_solver(matrix)
u = ml.solve(rhs, tol=1e-10)
return u
def solver(mesh):
matrix, rhs = pyfvm.discretize_linear(problem, mesh)
ml = pyamg.smoothed_aggregation_solver(matrix)
u = ml.solve(rhs, tol=1e-10)
return u
def solver(mesh):
matrix, rhs = pyfvm.discretize_linear(problem, mesh)
ml = pyamg.smoothed_aggregation_solver(matrix)
u = ml.solve(rhs, tol=1e-10)
return u
def solver(mesh):
matrix, rhs = pyfvm.discretize_linear(Poisson(), mesh)
ml = pyamg.smoothed_aggregation_solver(matrix)
u = ml.solve(rhs, tol=1e-10)
return u
def solver(mesh):
matrix, rhs = pyfvm.discretize_linear(Convection(), mesh)
ml = pyamg.smoothed_aggregation_solver(matrix)
u = ml.solve(rhs, tol=1e-10)
return u
eigen_values, eigen_vectors = scipy.linalg.eigh(
Phi, eigvals=(1, out_dim + 1), overwrite_a=True)
index = np.argsort(np.abs(eigen_values))
return eigen_vectors[:, index], np.sum(eigen_values)
elif eigen_solver == 'lobpcg':
from scipy.sparse import linalg, eye, csr_matrix
Phi = csr_matrix(Phi)
# initial approximation to the eigenvectors
X = np.random.rand(Phi.shape[0], out_dim+1)
try:
ml = pyamg.smoothed_aggregation_solver(Phi, symmetry='symmetric')
except TypeError:
ml = pyamg.smoothed_aggregation_solver(Phi, mat_flag='symmetric')
prec = ml.aspreconditioner()
# compute eigenvalues and eigenvectors with LOBPCG
eigen_values, eigen_vectors = linalg.lobpcg(
Phi, X, M=prec, largest=False, tol=tol, maxiter=max_iter)
index = np.argsort(eigen_values)
return eigen_vectors[:, index[1:]], np.sum(eigen_values[index[1:]])
else:
raise NotImplementedError('Method %s not implemented' % eigen_solver)
sigma=1.0, which='LM',
tol=eigen_tol)
embedding = diffusion_map.T[n_components::-1] * dd
except RuntimeError:
# When submatrices are exactly singular, an LU decomposition
# in arpack fails. We fallback to lobpcg
eigen_solver = "lobpcg"
if eigen_solver == 'amg':
# Use AMG to get a preconditioner and speed up the eigenvalue
# problem.
if not sparse.issparse(laplacian):
warnings.warn("AMG works better for sparse matrices")
laplacian = laplacian.astype(np.float) # lobpcg needs native floats
laplacian = _set_diag(laplacian, 1)
ml = smoothed_aggregation_solver(atleast2d_or_csr(laplacian))
M = ml.aspreconditioner()
X = random_state.rand(laplacian.shape[0], n_components + 1)
X[:, 0] = dd.ravel()
lambdas, diffusion_map = lobpcg(laplacian, X, M=M, tol=1.e-12,
largest=False)
embedding = diffusion_map.T * dd
if embedding.shape[0] == 1:
raise ValueError
elif eigen_solver == "lobpcg":
laplacian = laplacian.astype(np.float) # lobpcg needs native floats
if n_nodes < 5 * n_components + 1:
# see note above under arpack why lobpcg has problems with small
# number of nodes
# lobpcg will fallback to symeig, so we short circuit it
if sparse.isspmatrix(laplacian):
def __init__(self, conf, **kwargs):
try:
import pyamg
except ImportError:
msg = 'cannot import pyamg!'
raise ImportError(msg)
LinearSolver.__init__(self, conf, mg=None, **kwargs)
try:
solver = getattr(pyamg, self.conf.method)
except AttributeError:
output('pyamg.%s does not exist!' % self.conf.method)
output('using pyamg.smoothed_aggregation_solver instead')
solver = pyamg.smoothed_aggregation_solver
self.solver = solver