Skip to content

Commit 5704874

Browse files
Merge pull request #776 from jarrodmillman/sparse-typos
Fix LOBPCG Sakurai typos
2 parents c2338c9 + f58617e commit 5704874

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

advanced/scipy_sparse/examples/direct_solve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
mtx = sp.sparse.lil_array((1000, 1000), dtype=np.float64)
1717
mtx[0, :100] = rng.random(100)
18-
mtx[1, 100:200] = mtx[0, :100]
18+
mtx[1, 100:200] = mtx[[0], :100]
1919
mtx.setdiag(rng.random(1000))
2020

2121
plt.clf()
@@ -27,4 +27,4 @@
2727

2828
x = sp.sparse.linalg.spsolve(mtx, rhs)
2929

30-
print(f"residual: {np.linalg.norm(mtx * x - rhs)!r}")
30+
print(f"residual: {np.linalg.norm(mtx @ x - rhs)!r}")

advanced/scipy_sparse/examples/lobpcg_sakurai.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def sakurai(n):
2121
"""
2222

2323
A = sp.sparse.eye(n, n)
24-
d0 = np.array(r_[5, 6 * ones(n - 2), 5])
24+
d0 = np.hstack([5, 6 * np.ones(n - 2), 5])
2525
d1 = -4 * np.ones(n)
2626
d2 = np.ones(n)
2727
B = sp.sparse.spdiags([d2, d1, d0, d1, d2], [-2, -1, 0, 1, 2], n, n)
@@ -41,13 +41,19 @@ def sakurai(n):
4141
#
4242
n = 2500
4343
A, B, w_ex = sakurai(n) # Mikota pair
44-
X = np.rand(n, m)
44+
X = np.random.random((n, m))
4545
data = []
46-
tt = time.clock()
46+
tt = time.time()
4747
eigs, vecs, resnh = sp.sparse.linalg.lobpcg(
48-
A, X, B, tol=1e-6, maxiter=500, retResidualNormsHistory=1
48+
A,
49+
X,
50+
B,
51+
tol=1e-6,
52+
largest=False,
53+
maxiter=2000,
54+
retResidualNormsHistory=1,
4955
)
50-
data.append(time.clock() - tt)
56+
data.append(time.time() - tt)
5157
print("Results by LOBPCG for n=" + str(n))
5258
print()
5359
print(eigs)

advanced/scipy_sparse/examples/pyamg_with_lobpcg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Dirichlet boundary conditions.
88
"""
99

10+
import numpy as np
1011
import scipy as sp
1112
import matplotlib.pyplot as plt
1213

@@ -21,7 +22,7 @@
2122
ml = smoothed_aggregation_solver(A)
2223

2324
# initial approximation to the K eigenvectors
24-
X = sp.rand(A.shape[0], K)
25+
X = np.random.random((A.shape[0], K))
2526

2627
# preconditioner based on ml
2728
M = ml.aspreconditioner()

0 commit comments

Comments
 (0)