Skip to content

Commit 7eb1a41

Browse files
committed
🤖 Format .jl files
1 parent 9bc4177 commit 7eb1a41

File tree

1 file changed

+43
-42
lines changed

1 file changed

+43
-42
lines changed

src/utils.jl

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,29 @@ function opnorm_eig(B; max_attempts::Int = 3)
1818
ncv = max(20, 2 * nev + 1)
1919

2020
while !(have_eig || attempt >= max_attempts)
21-
attempt += 1
22-
try
23-
# Estimate largest eigenvalue in absolute value
24-
d, nconv, niter, nmult, resid = eigs(B; nev = nev, ncv = ncv, which = :LM, ritzvec = false, check = 1)
25-
26-
# Check if eigenvalue has converged
27-
have_eig = nconv == 1
28-
if have_eig
29-
λ = abs(d[1]) # Take absolute value of the largest eigenvalue
30-
break # Exit loop if successful
31-
else
32-
# Increase NCV for the next attempt if convergence wasn't achieved
33-
ncv = min(2 * ncv, n)
34-
end
35-
catch e
36-
if occursin("XYAUPD_Exception", string(e)) && ncv < n
37-
@warn "Arpack error: $e. Increasing NCV to $ncv and retrying."
38-
ncv = min(2 * ncv, n) # Increase NCV but don't exceed matrix size
39-
else
40-
rethrow(e) # Re-raise if it's a different error
41-
end
21+
attempt += 1
22+
try
23+
# Estimate largest eigenvalue in absolute value
24+
d, nconv, niter, nmult, resid =
25+
eigs(B; nev = nev, ncv = ncv, which = :LM, ritzvec = false, check = 1)
26+
27+
# Check if eigenvalue has converged
28+
have_eig = nconv == 1
29+
if have_eig
30+
λ = abs(d[1]) # Take absolute value of the largest eigenvalue
31+
break # Exit loop if successful
32+
else
33+
# Increase NCV for the next attempt if convergence wasn't achieved
34+
ncv = min(2 * ncv, n)
35+
end
36+
catch e
37+
if occursin("XYAUPD_Exception", string(e)) && ncv < n
38+
@warn "Arpack error: $e. Increasing NCV to $ncv and retrying."
39+
ncv = min(2 * ncv, n) # Increase NCV but don't exceed matrix size
40+
else
41+
rethrow(e) # Re-raise if it's a different error
4242
end
43+
end
4344
end
4445

4546
return λ, have_eig
@@ -54,28 +55,28 @@ function opnorm_svd(J; max_attempts::Int = 3)
5455
ncv = 10
5556

5657
while !(have_svd || attempt >= max_attempts)
57-
attempt += 1
58-
try
59-
# Estimate largest singular value
60-
s, nconv, niter, nmult, resid = svds(J; nsv = nsv, ncv = ncv, ritzvec = false, check = 1)
61-
62-
# Check if singular value has converged
63-
have_svd = nconv >= 1
64-
if have_svd
65-
σ = maximum(s.S) # Take the largest singular value
66-
break # Exit loop if successful
67-
else
68-
# Increase NCV for the next attempt if convergence wasn't achieved
69-
ncv = min(2 * ncv, n)
70-
end
71-
catch e
72-
if occursin("XYAUPD_Exception", string(e)) && ncv < n
73-
@warn "Arpack error: $e. Increasing NCV to $ncv and retrying."
74-
ncv = min(2 * ncv, n) # Increase NCV but don't exceed matrix size
75-
else
76-
rethrow(e) # Re-raise if it's a different error
77-
end
58+
attempt += 1
59+
try
60+
# Estimate largest singular value
61+
s, nconv, niter, nmult, resid = svds(J; nsv = nsv, ncv = ncv, ritzvec = false, check = 1)
62+
63+
# Check if singular value has converged
64+
have_svd = nconv >= 1
65+
if have_svd
66+
σ = maximum(s.S) # Take the largest singular value
67+
break # Exit loop if successful
68+
else
69+
# Increase NCV for the next attempt if convergence wasn't achieved
70+
ncv = min(2 * ncv, n)
71+
end
72+
catch e
73+
if occursin("XYAUPD_Exception", string(e)) && ncv < n
74+
@warn "Arpack error: $e. Increasing NCV to $ncv and retrying."
75+
ncv = min(2 * ncv, n) # Increase NCV but don't exceed matrix size
76+
else
77+
rethrow(e) # Re-raise if it's a different error
7878
end
79+
end
7980
end
8081

8182
return σ, have_svd

0 commit comments

Comments
 (0)