-
Notifications
You must be signed in to change notification settings - Fork 1
/
vec_col_one_rand_cyclic.jl
50 lines (39 loc) · 1.23 KB
/
vec_col_one_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
45
46
47
48
49
50
# This file is part of RLinearAlgebra.jl
# 1. Specifies type
# 2. Implements sample function
# 3. Exports Type
# using Random
"""
LinSysVecColOneRandCyclic <: LinSysVecColSelect
A mutable structure with a field to store a cycling order. Randomly specifies a cycling
order over the equations of a linear system. Once this ordering is specified, the ordering
is kept fixed.
# Fields
- `order::Vector{Int64}`
Calling `LinSysVecColOneRandCyclic()` defaults to setting `order` to `nothing`. The `sample`
function will handle the re-initialization of the fields once the system is provided.
"""
mutable struct LinSysVecColOneRandCyclic <: LinSysVecColSelect
order::Vector{Int64}
end
LinSysVecColOneRandCyclic() = LinSysVecColOneRandCyclic(Int64[])
# Common sample interface for linear systems
function sample(
type::LinSysVecColOneRandCyclic,
A::AbstractArray,
b::AbstractVector,
x::AbstractVector,
iter::Int64
)
if iter == 1
type.order = randperm(length(x))
end
col_idx = type.order[mod(iter, 1:length(x))]
# Search direction
v = zeros(length(x))
v[col_idx] = 1.0
# Normal equation residual
res = dot(A[:,col_ind], A * x - b)
return v, A, res
end
#export LinSysVecColOneRandCyclic