@@ -4,13 +4,13 @@ export jtprod_residual, jtprod_residual!, jac_op_residual, jac_op_residual!
4
4
export hess_residual, hess_structure_residual, hess_structure_residual!
5
5
export hess_coord_residual!, hess_coord_residual, jth_hess_residual
6
6
export hprod_residual, hprod_residual!, hess_op_residual, hess_op_residual!
7
- export project!, project
7
+ export project!, project, get_meta
8
8
9
9
"""
10
10
Fx = residual(model, x)
11
11
Computes ``F(x)``, the residual at x.
12
12
"""
13
- function residual (model:: AbstractVIModel{T, S} , x:: AbstractVector{T} ) where {T, S}
13
+ function NLPModels . residual (model:: AbstractVIModel{T, S} , x:: AbstractVector{T} ) where {T, S}
14
14
@lencheck model. meta. nvar x
15
15
Fx = S (undef, model. meta. nvar)
16
16
residual! (model, x, Fx)
@@ -26,7 +26,7 @@ function residual! end
26
26
Jx = jac_residual(model, x)
27
27
Computes ``J(x)``, the Jacobian of the residual at x.
28
28
"""
29
- function jac_residual (model:: AbstractVIModel , x:: AbstractVector )
29
+ function NLPModels . jac_residual (model:: AbstractVIModel , x:: AbstractVector )
30
30
@lencheck model. meta. nvar x
31
31
rows, cols = jac_structure_residual (model)
32
32
vals = jac_coord_residual (model, x)
@@ -43,9 +43,9 @@ function jac_structure_residual! end
43
43
(rows,cols) = jac_structure_residual(model)
44
44
Returns the structure of the constraint's Jacobian in sparse coordinate format.
45
45
"""
46
- function jac_structure_residual (model:: AbstractVIModel )
47
- rows = Vector {Int} (undef, model. nnzj)
48
- cols = Vector {Int} (undef, model. nnzj)
46
+ function NLPModels . jac_structure_residual (model:: AbstractVIModel )
47
+ rows = Vector {Int} (undef, model. meta . nnzj)
48
+ cols = Vector {Int} (undef, model. meta . nnzj)
49
49
jac_structure_residual! (model, rows, cols)
50
50
end
51
51
@@ -60,17 +60,17 @@ function jac_coord_residual! end
60
60
(rows,cols,vals) = jac_coord_residual(model, x)
61
61
Computes the Jacobian of the residual at `x` in sparse coordinate format.
62
62
"""
63
- function jac_coord_residual (model:: AbstractVIModel , x:: AbstractVector )
63
+ function NLPModels . jac_coord_residual (model:: AbstractVIModel , x:: AbstractVector )
64
64
@lencheck model. meta. nvar x
65
- vals = Vector {eltype(x)} (undef, model. nnzj)
65
+ vals = Vector {eltype(x)} (undef, model. meta . nnzj)
66
66
jac_coord_residual! (model, x, vals)
67
67
end
68
68
69
69
"""
70
70
Jv = jprod_residual(model, x, v)
71
71
Computes the product of the Jacobian of the residual at x and a vector, i.e., ``J(x)v``.
72
72
"""
73
- function jprod_residual (
73
+ function NLPModels . jprod_residual (
74
74
model:: AbstractVIModel{T, S} ,
75
75
x:: AbstractVector{T} ,
76
76
v:: AbstractVector ,
@@ -91,43 +91,25 @@ function jprod_residual! end
91
91
Computes the product of the Jacobian of the residual given by `(rows, cols, vals)`
92
92
and a vector, i.e., ``J(x)v``, storing it in `Jv`.
93
93
"""
94
- function jprod_residual! (
94
+ function NLPModels . jprod_residual! (
95
95
model:: AbstractVIModel ,
96
96
rows:: AbstractVector{<:Integer} ,
97
97
cols:: AbstractVector{<:Integer} ,
98
98
vals:: AbstractVector ,
99
99
v:: AbstractVector ,
100
100
Jv:: AbstractVector ,
101
101
)
102
- @lencheck model. nnzj rows cols vals
102
+ @lencheck model. meta . nnzj rows cols vals
103
103
@lencheck model. meta. nvar v Jv
104
104
increment! (model, :neval_jprod_residual )
105
105
coo_prod! (rows, cols, vals, v, Jv)
106
106
end
107
107
108
- """
109
- Jv = jprod_residual!(model, x, rows, cols, v, Jv)
110
- Computes the product of the Jacobian of the residual at x and a vector, i.e., ``J(x)v``, storing it in `Jv`.
111
- The structure of the Jacobian is given by `(rows, cols)`.
112
- """
113
- function jprod_residual! (
114
- model:: AbstractVIModel ,
115
- x:: AbstractVector ,
116
- rows:: AbstractVector{<:Integer} ,
117
- cols:: AbstractVector{<:Integer} ,
118
- v:: AbstractVector ,
119
- Jv:: AbstractVector ,
120
- )
121
- @lencheck model. meta. nvar x v Jv
122
- @lencheck model. nnzj rows cols
123
- jprod_residual! (model, x, v, Jv)
124
- end
125
-
126
108
"""
127
109
Jtv = jtprod_residual(model, x, v)
128
110
Computes the product of the transpose of the Jacobian of the residual at x and a vector, i.e., ``J(x)^Tv``.
129
111
"""
130
- function jtprod_residual (
112
+ function NLPModels . jtprod_residual (
131
113
model:: AbstractVIModel{T, S} ,
132
114
x:: AbstractVector{T} ,
133
115
v:: AbstractVector ,
@@ -148,104 +130,45 @@ function jtprod_residual! end
148
130
Computes the product of the transpose of the Jacobian of the residual given by `(rows, cols, vals)`
149
131
and a vector, i.e., ``J(x)^Tv``, storing it in `Jv`.
150
132
"""
151
- function jtprod_residual! (
133
+ function NLPModels . jtprod_residual! (
152
134
model:: AbstractVIModel ,
153
135
rows:: AbstractVector{<:Integer} ,
154
136
cols:: AbstractVector{<:Integer} ,
155
137
vals:: AbstractVector ,
156
138
v:: AbstractVector ,
157
139
Jtv:: AbstractVector ,
158
140
)
159
- @lencheck model. nnzj rows cols vals
141
+ @lencheck model. meta . nnzj rows cols vals
160
142
@lencheck model. meta. nvar v Jtv
161
143
increment! (model, :neval_jtprod_residual )
162
144
coo_prod! (cols, rows, vals, v, Jtv)
163
145
end
164
146
165
- """
166
- Jtv = jtprod_residual!(model, x, rows, cols, v, Jtv)
167
- Computes the product of the transpose Jacobian of the residual at x and a vector, i.e., ``J(x)^Tv``, storing it in `Jv`.
168
- The structure of the Jacobian is given by `(rows, cols)`.
169
- """
170
- function jtprod_residual! (
171
- model:: AbstractVIModel ,
172
- x:: AbstractVector ,
173
- rows:: AbstractVector{<:Integer} ,
174
- cols:: AbstractVector{<:Integer} ,
175
- v:: AbstractVector ,
176
- Jtv:: AbstractVector ,
177
- )
178
- @lencheck model. meta. nvar x v Jtv
179
- @lencheck model. nnzj rows cols
180
- jtprod_residual! (model, x, v, Jtv)
181
- end
182
-
183
147
"""
184
148
Jx = jac_op_residual(model, x)
185
149
Computes ``J(x)``, the Jacobian of the residual at x, in linear operator form.
186
150
"""
187
- function jac_op_residual (model:: AbstractVIModel{T, S} , x:: AbstractVector{T} ) where {T, S}
151
+ function NLPModels . jac_op_residual (model:: AbstractVIModel{T, S} , x:: AbstractVector{T} ) where {T, S}
188
152
@lencheck model. meta. nvar x
189
153
Jv = S (undef, model. meta. nvar)
190
154
Jtv = S (undef, model. meta. nvar)
191
155
return jac_op_residual! (model, x, Jv, Jtv)
192
156
end
193
157
194
- """
195
- Jx = jac_op_residual!(model, x, Jv, Jtv)
196
- Computes ``J(x)``, the Jacobian of the residual at x, in linear operator form. The
197
- vectors `Jv` and `Jtv` are used as preallocated storage for the operations.
198
- """
199
- function jac_op_residual! (
200
- model:: AbstractVIModel ,
201
- x:: AbstractVector ,
202
- Jv:: AbstractVector ,
203
- Jtv:: AbstractVector ,
204
- )
205
- @lencheck model. meta. nvar x Jv Jtv
206
- prod! = @closure (res, v, α, β) -> begin
207
- jprod_residual! (model, x, v, Jv)
208
- if β == 0
209
- @. res = α * Jv
210
- else
211
- @. res = α * Jv + β * res
212
- end
213
- return res
214
- end
215
- ctprod! = @closure (res, v, α, β) -> begin
216
- jtprod_residual! (model, x, v, Jtv)
217
- if β == 0
218
- @. res = α * Jtv
219
- else
220
- @. res = α * Jtv + β * res
221
- end
222
- return res
223
- end
224
- return LinearOperator {eltype(x)} (
225
- model. meta. nvar,
226
- model. meta. nvar,
227
- false ,
228
- false ,
229
- prod!,
230
- ctprod!,
231
- ctprod!,
232
- )
233
- end
234
-
235
158
"""
236
159
Jx = jac_op_residual!(model, rows, cols, vals, Jv, Jtv)
237
160
Computes ``J(x)``, the Jacobian of the residual given by `(rows, cols, vals)`, in linear operator form. The
238
161
vectors `Jv` and `Jtv` are used as preallocated storage for the operations.
239
162
"""
240
- function jac_op_residual! (
163
+ function NLPModels . jac_op_residual! (
241
164
model:: AbstractVIModel ,
242
165
rows:: AbstractVector{<:Integer} ,
243
166
cols:: AbstractVector{<:Integer} ,
244
167
vals:: AbstractVector ,
245
168
Jv:: AbstractVector ,
246
169
Jtv:: AbstractVector ,
247
170
)
248
- @lencheck model. nnzj rows cols vals
171
+ @lencheck model. meta . nnzj rows cols vals
249
172
@lencheck model. meta. nvar Jv Jtv
250
173
prod! = @closure (res, v, α, β) -> begin
251
174
jprod_residual! (model, rows, cols, vals, v, Jv)
@@ -276,34 +199,13 @@ function jac_op_residual!(
276
199
)
277
200
end
278
201
279
- """
280
- Jx = jac_op_residual!(model, x, rows, cols, Jv, Jtv)
281
- Computes ``J(x)``, the Jacobian of the residual at x, in linear operator form. The
282
- vectors `Jv` and `Jtv` are used as preallocated storage for the operations.
283
- The structure of the Jacobian should be given by `(rows, cols)`.
284
- """
285
- function jac_op_residual! (
286
- model:: AbstractVIModel ,
287
- x:: AbstractVector ,
288
- rows:: AbstractVector{<:Integer} ,
289
- cols:: AbstractVector{<:Integer} ,
290
- Jv:: AbstractVector ,
291
- Jtv:: AbstractVector ,
292
- )
293
- @lencheck model. meta. nvar x Jv Jtv
294
- @lencheck model. nnzj rows cols
295
- vals = jac_coord_residual (model, x)
296
- decrement! (model, :neval_jac_residual )
297
- return jac_op_residual! (model, rows, cols, vals, Jv, Jtv)
298
- end
299
-
300
202
"""
301
203
H = hess_residual(model, x, v)
302
204
Computes the linear combination of the Hessians of the residuals at `x` with coefficients
303
205
`v`.
304
206
A `Symmetric` object wrapping the lower triangle is returned.
305
207
"""
306
- function hess_residual (model:: AbstractVIModel , x:: AbstractVector , v:: AbstractVector )
208
+ function NLPModels . hess_residual (model:: AbstractVIModel , x:: AbstractVector , v:: AbstractVector )
307
209
@lencheck model. meta. nvar x v
308
210
rows, cols = hess_structure_residual (model)
309
211
vals = hess_coord_residual (model, x, v)
314
216
(rows,cols) = hess_structure_residual(model)
315
217
Returns the structure of the residual Hessian.
316
218
"""
317
- function hess_structure_residual (model:: AbstractVIModel )
318
- rows = Vector {Int} (undef, model. nnzh)
319
- cols = Vector {Int} (undef, model. nnzh)
219
+ function NLPModels . hess_structure_residual (model:: AbstractVIModel )
220
+ rows = Vector {Int} (undef, model. meta . nnzh)
221
+ cols = Vector {Int} (undef, model. meta . nnzh)
320
222
hess_structure_residual! (model, rows, cols)
321
223
end
322
224
@@ -338,17 +240,17 @@ function hess_coord_residual! end
338
240
Computes the linear combination of the Hessians of the residuals at `x` with coefficients
339
241
`v` in sparse coordinate format.
340
242
"""
341
- function hess_coord_residual (model:: AbstractVIModel , x:: AbstractVector , v:: AbstractVector )
243
+ function NLPModels . hess_coord_residual (model:: AbstractVIModel , x:: AbstractVector , v:: AbstractVector )
342
244
@lencheck model. meta. nvar x v
343
- vals = Vector {eltype(x)} (undef, model. nnzh)
245
+ vals = Vector {eltype(x)} (undef, model. meta . nnzh)
344
246
hess_coord_residual! (model, x, v, vals)
345
247
end
346
248
347
249
"""
348
250
Hj = jth_hess_residual(model, x, j)
349
251
Computes the Hessian of the j-th residual at x.
350
252
"""
351
- function jth_hess_residual (model:: AbstractVIModel , x:: AbstractVector , j:: Int )
253
+ function NLPModels . jth_hess_residual (model:: AbstractVIModel , x:: AbstractVector , j:: Int )
352
254
@lencheck model. meta. nvar x
353
255
increment! (model, :neval_jhess_residual )
354
256
decrement! (model, :neval_hess_residual )
360
262
Hiv = hprod_residual(model, x, i, v)
361
263
Computes the product of the Hessian of the i-th residual at x, times the vector v.
362
264
"""
363
- function hprod_residual (
265
+ function NLPModels . hprod_residual (
364
266
model:: AbstractVIModel{T, S} ,
365
267
x:: AbstractVector{T} ,
366
268
i:: Int ,
@@ -381,38 +283,12 @@ function hprod_residual! end
381
283
Hop = hess_op_residual(model, x, i)
382
284
Computes the Hessian of the i-th residual at x, in linear operator form.
383
285
"""
384
- function hess_op_residual (model:: AbstractVIModel{T, S} , x:: AbstractVector{T} , i:: Int ) where {T, S}
286
+ function NLPModels . hess_op_residual (model:: AbstractVIModel{T, S} , x:: AbstractVector{T} , i:: Int ) where {T, S}
385
287
@lencheck model. meta. nvar x
386
288
Hiv = S (undef, model. meta. nvar)
387
289
return hess_op_residual! (model, x, i, Hiv)
388
290
end
389
291
390
- """
391
- Hop = hess_op_residual!(model, x, i, Hiv)
392
- Computes the Hessian of the i-th residual at x, in linear operator form. The vector `Hiv` is used as preallocated storage for the operation.
393
- """
394
- function hess_op_residual! (model:: AbstractVIModel , x:: AbstractVector , i:: Int , Hiv:: AbstractVector )
395
- @lencheck model. meta. nvar x Hiv
396
- prod! = @closure (res, v, α, β) -> begin
397
- hprod_residual! (model, x, i, v, Hiv)
398
- if β == 0
399
- @. res = α * Hiv
400
- else
401
- @. res = α * Hiv + β * res
402
- end
403
- return res
404
- end
405
- return LinearOperator {eltype(x)} (
406
- model. meta. nvar,
407
- model. meta. nvar,
408
- true ,
409
- true ,
410
- prod!,
411
- prod!,
412
- prod!,
413
- )
414
- end
415
-
416
292
get_meta (model:: AbstractVIModel ) = model. meta
417
293
418
294
"""
0 commit comments