@@ -78,6 +78,18 @@ function push!(
78
78
return B
79
79
end
80
80
81
+ """
82
+ reset!(op::DiagonalQN)
83
+ Resets the DiagonalQN data of the given operator.
84
+ """
85
+ function reset! (op:: DiagonalQN{T} ) where {T <: Real }
86
+ op. d .= one (T)
87
+ op. nprod = 0
88
+ op. ntprod = 0
89
+ op. nctprod = 0
90
+ return op
91
+ end
92
+
81
93
"""
82
94
Implementation of a spectral gradient quasi-Newton approximation described in
83
95
@@ -87,7 +99,7 @@ https://doi.org/10.18637/jss.v060.i03
87
99
"""
88
100
mutable struct SpectralGradient{T <: Real , I <: Integer , F} < :
89
101
AbstractDiagonalQuasiNewtonOperator{T}
90
- d:: T # Diagonal coefficient of the operator (multiple of the identity)
102
+ d:: Vector{T} # Diagonal coefficient of the operator (multiple of the identity)
91
103
nrow:: I
92
104
ncol:: I
93
105
symmetric:: Bool
@@ -114,8 +126,9 @@ The approximation is defined as σI.
114
126
- `σ::Real`: initial positive multiple of the identity;
115
127
- `n::Int`: operator size.
116
128
"""
117
- function SpectralGradient (d:: T , n:: I ) where {T <: Real , I <: Integer }
118
- @assert d > 0
129
+ function SpectralGradient (σ:: T , n:: I ) where {T <: Real , I <: Integer }
130
+ @assert σ > 0
131
+ d = [σ]
119
132
prod = (res, v, α, β) -> mulSquareOpDiagonal! (res, d, v, α, β)
120
133
SpectralGradient (d, n, n, true , true , prod, prod, prod, 0 , 0 , 0 , true , true , true )
121
134
end
@@ -131,6 +144,18 @@ function push!(
131
144
if all (s .== 0 )
132
145
error (" Cannot divide by zero and s .= 0" )
133
146
end
134
- B. d = dot (s, y) / dot (s, s)
147
+ B. d[ 1 ] = dot (s, y) / dot (s, s)
135
148
return B
136
149
end
150
+
151
+ """
152
+ reset!(op::SpectralGradient)
153
+ Resets the SpectralGradient data of the given operator.
154
+ """
155
+ function reset! (op:: SpectralGradient{T} ) where {T <: Real }
156
+ op. d[1 ] = one (T)
157
+ op. nprod = 0
158
+ op. ntprod = 0
159
+ op. nctprod = 0
160
+ return op
161
+ end
0 commit comments