|
1 | 1 | import LinearAlgebra: mul!, ldiv! |
2 | | -import Base: start, next, done, getindex |
| 2 | +import Base: getindex, iterate |
3 | 3 |
|
4 | 4 | using SparseArrays |
5 | 5 |
|
|
222 | 222 |
|
223 | 223 | start(::JacobiIterable) = 1 |
224 | 224 | done(j::JacobiIterable, iteration::Int) = iteration > j.maxiter |
225 | | -function next(j::JacobiIterable{T}, iteration::Int) where {T} |
| 225 | +function iterate(j::JacobiIterable{T}, iteration::Int=start(j)) where {T} |
| 226 | + if done(j, iteration) return nothing end |
226 | 227 | # tmp = D \ (b - (A - D) * x) |
227 | 228 | copyto!(j.next, j.b) |
228 | 229 | mul!(-one(T), j.O, j.x, one(T), j.next) |
|
273 | 274 |
|
274 | 275 | start(::GaussSeidelIterable) = 1 |
275 | 276 | done(g::GaussSeidelIterable, iteration::Int) = iteration > g.maxiter |
276 | | -function next(g::GaussSeidelIterable, iteration::Int) |
| 277 | +function iterate(g::GaussSeidelIterable, iteration::Int=start(g)) |
| 278 | + if done(g, iteration) return nothing end |
277 | 279 | # x ← L \ (-U * x + b) |
278 | 280 | T = eltype(g.x) |
279 | 281 | gauss_seidel_multiply!(-one(T), g.U, g.x, one(T), g.b, g.x) |
|
316 | 318 |
|
317 | 319 | start(::SORIterable) = 1 |
318 | 320 | done(s::SORIterable, iteration::Int) = iteration > s.maxiter |
319 | | -function next(s::SORIterable{T}, iteration::Int) where {T} |
| 321 | +function iterate(s::SORIterable{T}, iteration::Int=start(s)) where {T} |
| 322 | + if done(s, iteration) return nothing end |
| 323 | + |
320 | 324 | # next = b - U * x |
321 | 325 | gauss_seidel_multiply!(-one(T), s.U, s.x, one(T), s.b, s.next) |
322 | 326 |
|
|
384 | 388 | start(s::SSORIterable) = 1 |
385 | 389 | done(s::SSORIterable, iteration::Int) = iteration > s.maxiter |
386 | 390 |
|
387 | | -function next(s::SSORIterable{T}, iteration::Int) where {T} |
| 391 | +function iterate(s::SSORIterable{T}, iteration::Int=start(s)) where {T} |
| 392 | + if done(s, iteration) return nothing end |
| 393 | + |
388 | 394 | # tmp = b - U * x |
389 | 395 | gauss_seidel_multiply!(-one(T), s.sU, s.x, one(T), s.b, s.tmp) |
390 | 396 |
|
|
0 commit comments