@@ -24,14 +24,14 @@ type LinesearchMethod struct {
24
24
first bool // Indicator of the first iteration.
25
25
nextMajor bool // Indicates that MajorIteration must be requested at the next call to Iterate().
26
26
27
- loc Location // Storage for intermediate locations.
28
- eval RequestType // Indicator of valid fields in loc.
27
+ loc Location // Storage for intermediate locations.
28
+ eval Operation // Indicator of valid fields in loc.
29
29
30
- lastStep float64 // Step taken from x in the previous call to Iterate().
31
- lastRequest RequestType // Request returned from the previous call to Iterate().
30
+ lastStep float64 // Step taken from x in the previous call to Iterate().
31
+ lastOp Operation // Operation returned from the previous call to Iterate().
32
32
}
33
33
34
- func (ls * LinesearchMethod ) Init (loc * Location ) (RequestType , error ) {
34
+ func (ls * LinesearchMethod ) Init (loc * Location ) (Operation , error ) {
35
35
if loc .Gradient == nil {
36
36
panic ("linesearch: gradient is nil" )
37
37
}
@@ -51,14 +51,14 @@ func (ls *LinesearchMethod) Init(loc *Location) (RequestType, error) {
51
51
}
52
52
53
53
ls .lastStep = math .NaN ()
54
- ls .lastRequest = NoRequest
54
+ ls .lastOp = NoOperation
55
55
56
56
return ls .initNextLinesearch (loc .X )
57
57
}
58
58
59
- func (ls * LinesearchMethod ) Iterate (loc * Location ) (RequestType , error ) {
60
- switch ls .lastRequest {
61
- case NoRequest :
59
+ func (ls * LinesearchMethod ) Iterate (loc * Location ) (Operation , error ) {
60
+ switch ls .lastOp {
61
+ case NoOperation :
62
62
// TODO(vladimir-ch): We have previously returned with an error and
63
63
// Init() was not called. What to do? What about ls's internal state?
64
64
@@ -69,22 +69,22 @@ func (ls *LinesearchMethod) Iterate(loc *Location) (RequestType, error) {
69
69
return ls .initNextLinesearch (loc .X )
70
70
71
71
default :
72
- if ls .lastRequest & EvaluationRequest == 0 {
73
- panic ("linesearch: unexpected request " )
72
+ if ! ls .lastOp . IsEvaluation () {
73
+ panic ("linesearch: unexpected operation " )
74
74
}
75
75
76
76
// Store the result of the previously requested evaluation into ls.loc.
77
- if ls .lastRequest & FuncEvaluation != 0 {
77
+ if ls .lastOp & FuncEvaluation != 0 {
78
78
ls .loc .F = loc .F
79
79
}
80
- if ls .lastRequest & GradEvaluation != 0 {
80
+ if ls .lastOp & GradEvaluation != 0 {
81
81
copy (ls .loc .Gradient , loc .Gradient )
82
82
}
83
- if ls .lastRequest & HessEvaluation != 0 {
83
+ if ls .lastOp & HessEvaluation != 0 {
84
84
ls .loc .Hessian .CopySym (loc .Hessian )
85
85
}
86
86
// Update the indicator of valid fields of ls.loc.
87
- ls .eval |= ls .lastRequest
87
+ ls .eval |= ls .lastOp
88
88
89
89
if ls .nextMajor {
90
90
ls .nextMajor = false
@@ -94,26 +94,26 @@ func (ls *LinesearchMethod) Iterate(loc *Location) (RequestType, error) {
94
94
// can announce MajorIteration.
95
95
96
96
copyLocation (loc , & ls .loc )
97
- ls .lastRequest = MajorIteration
98
- return ls .lastRequest , nil
97
+ ls .lastOp = MajorIteration
98
+ return ls .lastOp , nil
99
99
}
100
100
}
101
101
102
102
projGrad := floats .Dot (ls .loc .Gradient , ls .dir )
103
103
if ls .Linesearcher .Finished (ls .loc .F , projGrad ) {
104
- // Form a request that evaluates invalid fields of ls.loc.
105
- ls .lastRequest = complementEval (& ls .loc , ls .eval )
106
- if ls .lastRequest == NoRequest {
104
+ // Form an operation that evaluates invalid fields of ls.loc.
105
+ ls .lastOp = complementEval (& ls .loc , ls .eval )
106
+ if ls .lastOp == NoOperation {
107
107
// ls.loc is complete and MajorIteration can be announced directly.
108
108
copyLocation (loc , & ls .loc )
109
- ls .lastRequest = MajorIteration
109
+ ls .lastOp = MajorIteration
110
110
} else {
111
111
ls .nextMajor = true
112
112
}
113
- return ls .lastRequest , nil
113
+ return ls .lastOp , nil
114
114
}
115
115
116
- step , request , err := ls .Linesearcher .Iterate (ls .loc .F , projGrad )
116
+ step , op , err := ls .Linesearcher .Iterate (ls .loc .F , projGrad )
117
117
if err != nil {
118
118
return ls .error (err )
119
119
}
@@ -132,26 +132,26 @@ func (ls *LinesearchMethod) Iterate(loc *Location) (RequestType, error) {
132
132
133
133
ls .lastStep = step
134
134
copy (ls .loc .X , loc .X ) // Move ls.loc to the next evaluation point
135
- ls .eval = NoRequest // and invalidate all its fields.
135
+ ls .eval = NoOperation // and invalidate all its fields.
136
136
} else {
137
137
// Linesearcher is requesting another evaluation at the same point
138
138
// which is stored in ls.loc.X.
139
139
copy (loc .X , ls .loc .X )
140
140
}
141
141
142
- ls .lastRequest = request
143
- return ls .lastRequest , nil
142
+ ls .lastOp = op
143
+ return ls .lastOp , nil
144
144
}
145
145
146
- func (ls * LinesearchMethod ) error (err error ) (RequestType , error ) {
147
- ls .lastRequest = NoRequest
148
- return ls .lastRequest , err
146
+ func (ls * LinesearchMethod ) error (err error ) (Operation , error ) {
147
+ ls .lastOp = NoOperation
148
+ return ls .lastOp , err
149
149
}
150
150
151
151
// initNextLinesearch initializes the next linesearch using the previous
152
- // complete location stored in ls.loc. It fills xNext and returns an
153
- // evaluation request to be performed at xNext.
154
- func (ls * LinesearchMethod ) initNextLinesearch (xNext []float64 ) (RequestType , error ) {
152
+ // complete location stored in ls.loc. It fills xNext and returns an evaluation
153
+ // to be performed at xNext.
154
+ func (ls * LinesearchMethod ) initNextLinesearch (xNext []float64 ) (Operation , error ) {
155
155
copy (ls .x , ls .loc .X )
156
156
157
157
var step float64
@@ -167,7 +167,7 @@ func (ls *LinesearchMethod) initNextLinesearch(xNext []float64) (RequestType, er
167
167
return ls .error (ErrNonNegativeStepDirection )
168
168
}
169
169
170
- ls .lastRequest = ls .Linesearcher .Init (ls .loc .F , projGrad , step )
170
+ ls .lastOp = ls .Linesearcher .Init (ls .loc .F , projGrad , step )
171
171
172
172
floats .AddScaledTo (xNext , ls .x , step , ls .dir )
173
173
if floats .Equal (ls .x , xNext ) {
@@ -179,9 +179,9 @@ func (ls *LinesearchMethod) initNextLinesearch(xNext []float64) (RequestType, er
179
179
180
180
ls .lastStep = step
181
181
copy (ls .loc .X , xNext ) // Move ls.loc to the next evaluation point
182
- ls .eval = NoRequest // and invalidate all its fields.
182
+ ls .eval = NoOperation // and invalidate all its fields.
183
183
184
- return ls .lastRequest , nil
184
+ return ls .lastOp , nil
185
185
}
186
186
187
187
// ArmijoConditionMet returns true if the Armijo condition (aka sufficient
0 commit comments