Skip to content

Commit ed830ae

Browse files
lostellamohamed82008
authored andcommitted
updated spdiagm syntax
1 parent 3bd5c5c commit ed830ae

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

benchmark/advection_diffusion.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function advection_dominated(;N = 50, β = 1000.0)
1919
Δ = laplace_matrix(Float64, N, 3) ./ -h^2
2020

2121
# And the dx bit.
22-
∂x_1d = spdiagm((fill(-β / 2h, N - 1), fill/ 2h, N - 1)), (-1, 1))
22+
∂x_1d = spdiagm(-1 => fill(-β / 2h, N - 1), 1 => fill/ 2h, N - 1))
2323
∂x = kron(speye(N^2), ∂x_1d)
2424

2525
# Final matrix and rhs.
@@ -41,6 +41,6 @@ function laplace_matrix(::Type{T}, n, dims) where T
4141
end
4242

4343
second_order_central_diff(::Type{T}, dim) where {T} = convert(
44-
SparseMatrixCSC{T, Int},
44+
SparseMatrixCSC{T, Int},
4545
SymTridiagonal(fill(2 * one(T), dim), fill(-one(T), dim - 1))
46-
)
46+
)

test/lsmr.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ suitably padded by zeros.
107107
"""
108108
function sol_matrix(m, n)
109109
mn = min(m, n)
110-
spdiagm((1.0 : mn - 1, 1.0 : mn), (-1, 0), m, n)
110+
I, J, V = SparseArrays.spdiagm_internal(-1 => 1.0 : mn - 1, 0 => 1.0 : mn)
111+
sparse(I, J, V, m, n)
111112
end
112113

113114
@testset "LSMR" begin

test/lsqr.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ end
2121

2222
function sol_matrix(m, n)
2323
mn = min(m, n)
24-
spdiagm((1.0 : mn - 1, 1.0 : mn), (-1, 0), m, n)
24+
I, J, V = SparseArrays.spdiagm_internal(-1 => 1.0 : mn - 1, 0 => 1.0 : mn)
25+
sparse(I, J, V, m, n)
2526
end
2627

2728
@testset "SOL test" for (m, n) = ((10, 10), (20, 10), (20, 10))

0 commit comments

Comments
 (0)