@@ -4,13 +4,13 @@ export jtprod_residual, jtprod_residual!, jac_op_residual, jac_op_residual!
44export hess_residual, hess_structure_residual, hess_structure_residual!
55export hess_coord_residual!, hess_coord_residual, jth_hess_residual
66export hprod_residual, hprod_residual!, hess_op_residual, hess_op_residual!
7- export project!, project
7+ export project!, project, get_meta
88
99"""
1010 Fx = residual(model, x)
1111Computes ``F(x)``, the residual at x.
1212"""
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}
1414 @lencheck model. meta. nvar x
1515 Fx = S(undef, model. meta. nvar)
1616 residual!(model, x, Fx)
@@ -26,7 +26,7 @@ function residual! end
2626 Jx = jac_residual(model, x)
2727Computes ``J(x)``, the Jacobian of the residual at x.
2828"""
29- function jac_residual(model:: AbstractVIModel , x:: AbstractVector )
29+ function NLPModels . jac_residual(model:: AbstractVIModel , x:: AbstractVector )
3030 @lencheck model. meta. nvar x
3131 rows, cols = jac_structure_residual(model)
3232 vals = jac_coord_residual(model, x)
@@ -43,9 +43,9 @@ function jac_structure_residual! end
4343 (rows,cols) = jac_structure_residual(model)
4444Returns the structure of the constraint's Jacobian in sparse coordinate format.
4545"""
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)
4949 jac_structure_residual!(model, rows, cols)
5050end
5151
@@ -60,17 +60,17 @@ function jac_coord_residual! end
6060 (rows,cols,vals) = jac_coord_residual(model, x)
6161Computes the Jacobian of the residual at `x` in sparse coordinate format.
6262"""
63- function jac_coord_residual(model:: AbstractVIModel , x:: AbstractVector )
63+ function NLPModels . jac_coord_residual(model:: AbstractVIModel , x:: AbstractVector )
6464 @lencheck model. meta. nvar x
65- vals = Vector{eltype(x)}(undef, model. nnzj)
65+ vals = Vector{eltype(x)}(undef, model. meta . nnzj)
6666 jac_coord_residual!(model, x, vals)
6767end
6868
6969"""
7070 Jv = jprod_residual(model, x, v)
7171Computes the product of the Jacobian of the residual at x and a vector, i.e., ``J(x)v``.
7272"""
73- function jprod_residual(
73+ function NLPModels . jprod_residual(
7474 model:: AbstractVIModel{T, S} ,
7575 x:: AbstractVector{T} ,
7676 v:: AbstractVector ,
@@ -91,43 +91,25 @@ function jprod_residual! end
9191Computes the product of the Jacobian of the residual given by `(rows, cols, vals)`
9292and a vector, i.e., ``J(x)v``, storing it in `Jv`.
9393"""
94- function jprod_residual!(
94+ function NLPModels . jprod_residual!(
9595 model:: AbstractVIModel ,
9696 rows:: AbstractVector{<:Integer} ,
9797 cols:: AbstractVector{<:Integer} ,
9898 vals:: AbstractVector ,
9999 v:: AbstractVector ,
100100 Jv:: AbstractVector ,
101101)
102- @lencheck model. nnzj rows cols vals
102+ @lencheck model. meta . nnzj rows cols vals
103103 @lencheck model. meta. nvar v Jv
104104 increment!(model, :neval_jprod_residual)
105105 coo_prod!(rows, cols, vals, v, Jv)
106106end
107107
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-
126108"""
127109 Jtv = jtprod_residual(model, x, v)
128110Computes the product of the transpose of the Jacobian of the residual at x and a vector, i.e., ``J(x)^Tv``.
129111"""
130- function jtprod_residual(
112+ function NLPModels . jtprod_residual(
131113 model:: AbstractVIModel{T, S} ,
132114 x:: AbstractVector{T} ,
133115 v:: AbstractVector ,
@@ -148,104 +130,45 @@ function jtprod_residual! end
148130Computes the product of the transpose of the Jacobian of the residual given by `(rows, cols, vals)`
149131and a vector, i.e., ``J(x)^Tv``, storing it in `Jv`.
150132"""
151- function jtprod_residual!(
133+ function NLPModels . jtprod_residual!(
152134 model:: AbstractVIModel ,
153135 rows:: AbstractVector{<:Integer} ,
154136 cols:: AbstractVector{<:Integer} ,
155137 vals:: AbstractVector ,
156138 v:: AbstractVector ,
157139 Jtv:: AbstractVector ,
158140)
159- @lencheck model. nnzj rows cols vals
141+ @lencheck model. meta . nnzj rows cols vals
160142 @lencheck model. meta. nvar v Jtv
161143 increment!(model, :neval_jtprod_residual)
162144 coo_prod!(cols, rows, vals, v, Jtv)
163145end
164146
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-
183147"""
184148 Jx = jac_op_residual(model, x)
185149Computes ``J(x)``, the Jacobian of the residual at x, in linear operator form.
186150"""
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}
188152 @lencheck model. meta. nvar x
189153 Jv = S(undef, model. meta. nvar)
190154 Jtv = S(undef, model. meta. nvar)
191155 return jac_op_residual!(model, x, Jv, Jtv)
192156end
193157
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-
235158"""
236159 Jx = jac_op_residual!(model, rows, cols, vals, Jv, Jtv)
237160Computes ``J(x)``, the Jacobian of the residual given by `(rows, cols, vals)`, in linear operator form. The
238161vectors `Jv` and `Jtv` are used as preallocated storage for the operations.
239162"""
240- function jac_op_residual!(
163+ function NLPModels . jac_op_residual!(
241164 model:: AbstractVIModel ,
242165 rows:: AbstractVector{<:Integer} ,
243166 cols:: AbstractVector{<:Integer} ,
244167 vals:: AbstractVector ,
245168 Jv:: AbstractVector ,
246169 Jtv:: AbstractVector ,
247170)
248- @lencheck model. nnzj rows cols vals
171+ @lencheck model. meta . nnzj rows cols vals
249172 @lencheck model. meta. nvar Jv Jtv
250173 prod! = @closure (res, v, α, β) -> begin
251174 jprod_residual!(model, rows, cols, vals, v, Jv)
@@ -276,34 +199,13 @@ function jac_op_residual!(
276199 )
277200end
278201
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-
300202"""
301203 H = hess_residual(model, x, v)
302204Computes the linear combination of the Hessians of the residuals at `x` with coefficients
303205`v`.
304206A `Symmetric` object wrapping the lower triangle is returned.
305207"""
306- function hess_residual(model:: AbstractVIModel , x:: AbstractVector , v:: AbstractVector )
208+ function NLPModels . hess_residual(model:: AbstractVIModel , x:: AbstractVector , v:: AbstractVector )
307209 @lencheck model. meta. nvar x v
308210 rows, cols = hess_structure_residual(model)
309211 vals = hess_coord_residual(model, x, v)
314216 (rows,cols) = hess_structure_residual(model)
315217Returns the structure of the residual Hessian.
316218"""
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)
320222 hess_structure_residual!(model, rows, cols)
321223end
322224
@@ -338,17 +240,17 @@ function hess_coord_residual! end
338240Computes the linear combination of the Hessians of the residuals at `x` with coefficients
339241`v` in sparse coordinate format.
340242"""
341- function hess_coord_residual(model:: AbstractVIModel , x:: AbstractVector , v:: AbstractVector )
243+ function NLPModels . hess_coord_residual(model:: AbstractVIModel , x:: AbstractVector , v:: AbstractVector )
342244 @lencheck model. meta. nvar x v
343- vals = Vector{eltype(x)}(undef, model. nnzh)
245+ vals = Vector{eltype(x)}(undef, model. meta . nnzh)
344246 hess_coord_residual!(model, x, v, vals)
345247end
346248
347249"""
348250 Hj = jth_hess_residual(model, x, j)
349251Computes the Hessian of the j-th residual at x.
350252"""
351- function jth_hess_residual(model:: AbstractVIModel , x:: AbstractVector , j:: Int )
253+ function NLPModels . jth_hess_residual(model:: AbstractVIModel , x:: AbstractVector , j:: Int )
352254 @lencheck model. meta. nvar x
353255 increment!(model, :neval_jhess_residual)
354256 decrement!(model, :neval_hess_residual)
360262 Hiv = hprod_residual(model, x, i, v)
361263Computes the product of the Hessian of the i-th residual at x, times the vector v.
362264"""
363- function hprod_residual(
265+ function NLPModels . hprod_residual(
364266 model:: AbstractVIModel{T, S} ,
365267 x:: AbstractVector{T} ,
366268 i:: Int ,
@@ -381,38 +283,12 @@ function hprod_residual! end
381283 Hop = hess_op_residual(model, x, i)
382284Computes the Hessian of the i-th residual at x, in linear operator form.
383285"""
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}
385287 @lencheck model. meta. nvar x
386288 Hiv = S(undef, model. meta. nvar)
387289 return hess_op_residual!(model, x, i, Hiv)
388290end
389291
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-
416292get_meta(model:: AbstractVIModel ) = model. meta
417293
418294"""
0 commit comments