-
Notifications
You must be signed in to change notification settings - Fork 1
/
vec_row_rand_cyclic.jl
44 lines (35 loc) · 1.18 KB
/
vec_row_rand_cyclic.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# This file is pat of RLinearAlgebra.jl
# 1. Specifies type
# 2. Implements sample function
# 3. Exports Type
# using Random
"""
LinSysVecRowRandCyclic <: LinSysVecRowSelect
A mutable structure with a field to store a cycling order. Randomly specifies a cycling
order the equations of a linear system. Once this ordering is exhausted by the solver,
a new random ordering is specified. This process is repeated
# Fields
- `order::Union{Vector{Int64},Nothing}`
Calling `LinSysVecRowOneRandCyclic()` defaults to setting `order` to `nothing`. The `sample`
function will handle the re-initialization of the fields once the system is provided.
"""
mutable struct LinSysVecRowRandCyclic <: LinSysVecRowSelect
order::Union{Vector{Int64},Nothing}
end
LinSysVecRowRandCyclic() = LinSysVecRowRandCyclic(nothing)
# Common sample interface for linear systems
function sample(
type::LinSysVecRowRandCyclic,
A::AbstractArray,
b::AbstractVector,
x::AbstractVector,
iter::Int64
)
mod_ind = mod(iter, 1:length(b))
if mod_ind == 1
type.order = randperm(length(b))
end
eqn_ind = type.order[mod_ind]
return A[eqn_ind, :], b[eqn_ind]
end
#export LinSysVecRowRandCyclic