Skip to content

Commit 79ff438

Browse files
committed
Update allocs_model.jl
1 parent 64a39ae commit 79ff438

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

src/allocs_model.jl

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,16 @@ function test_obj_grad!(nlp_allocations, nls::AbstractNLSModel, exclude)
239239
end
240240

241241
"""
242-
test_allocs_nlsmodels(nlp::AbstractNLSModel; exclude = [])
242+
test_allocs_nlsmodels(nls::AbstractNLSModel; exclude = [])
243243
244244
Returns a `Dict` containing allocations of the in-place functions specialized to nonlinear least squares of NLPModel API.
245245
246246
The keyword `exclude` takes a Array of Function to be excluded from the tests.
247247
Use `hess_residual` (resp. `jac_residual`) to exclude `hess_residual_coord` and `hess_residual_structure` (resp. `jac_residual_coord` and `jac_residual_structure`).
248248
The hessian-vector product is tested for all the component of the residual function, so exclude `hprod_residual` and `hess_op_residual` if you want to avoid this.
249249
"""
250-
function test_allocs_nlsmodels(nlp::AbstractNLSModel; exclude = [])
251-
nlp_allocations = Dict(
250+
function test_allocs_nlsmodels(nls::AbstractNLSModel; exclude = [])
251+
nls_allocations = Dict(
252252
:residual! => NaN,
253253
:hess_structure_residual! => NaN,
254254
:hess_coord_residual! => NaN,
@@ -263,85 +263,85 @@ function test_allocs_nlsmodels(nlp::AbstractNLSModel; exclude = [])
263263
)
264264

265265
if !(residual in exclude)
266-
x = get_x0(nlp)
267-
Fx = Vector{eltype(x)}(undef, get_nequ(nlp))
268-
residual!(nlp, x, Fx)
269-
nlp_allocations[:residual!] = @allocated residual!(nlp, x, Fx)
266+
x = get_x0(nls)
267+
Fx = Vector{eltype(x)}(undef, get_nequ(nls))
268+
residual!(nls, x, Fx)
269+
nls_allocations[:residual!] = @allocated residual!(nls, x, Fx)
270270
end
271271

272272
if !(jac_residual in exclude) && nls_meta(nls).jac_residual_available
273-
rows = Vector{Int}(undef, nlp.nls_meta.nnzj)
274-
cols = Vector{Int}(undef, nlp.nls_meta.nnzj)
275-
jac_structure_residual!(nlp, rows, cols)
276-
nlp_allocations[:jac_structure_residual!] = @allocated jac_structure_residual!(nlp, rows, cols)
277-
x = get_x0(nlp)
278-
vals = Vector{eltype(x)}(undef, nlp.nls_meta.nnzj)
279-
jac_coord_residual!(nlp, x, vals)
280-
nlp_allocations[:jac_coord_residual!] = @allocated jac_coord_residual!(nlp, x, vals)
273+
rows = Vector{Int}(undef, nls.nls_meta.nnzj)
274+
cols = Vector{Int}(undef, nls.nls_meta.nnzj)
275+
jac_structure_residual!(nls, rows, cols)
276+
nls_allocations[:jac_structure_residual!] = @allocated jac_structure_residual!(nls, rows, cols)
277+
x = get_x0(nls)
278+
vals = Vector{eltype(x)}(undef, nls.nls_meta.nnzj)
279+
jac_coord_residual!(nls, x, vals)
280+
nls_allocations[:jac_coord_residual!] = @allocated jac_coord_residual!(nls, x, vals)
281281
end
282282

283283
if !(jprod_residual in exclude) && nls_meta(nls).jprod_residual_available
284-
x = get_x0(nlp)
284+
x = get_x0(nls)
285285
v = copy(x)
286-
Jv = Vector{eltype(x)}(undef, get_nequ(nlp))
287-
jprod_residual!(nlp, x, v, Jv)
288-
nlp_allocations[:jprod_residual!] = @allocated jprod_residual!(nlp, x, v, Jv)
286+
Jv = Vector{eltype(x)}(undef, get_nequ(nls))
287+
jprod_residual!(nls, x, v, Jv)
288+
nls_allocations[:jprod_residual!] = @allocated jprod_residual!(nls, x, v, Jv)
289289
end
290290

291291
if !(jtprod_residual in exclude) && nls_meta(nls).jtprod_residual_available
292-
x = get_x0(nlp)
293-
w = zeros(eltype(x), get_nequ(nlp))
292+
x = get_x0(nls)
293+
w = zeros(eltype(x), get_nequ(nls))
294294
Jtv = similar(x)
295-
jtprod_residual!(nlp, x, w, Jtv)
296-
nlp_allocations[:jtprod_residual!] = @allocated jtprod_residual!(nlp, x, w, Jtv)
295+
jtprod_residual!(nls, x, w, Jtv)
296+
nls_allocations[:jtprod_residual!] = @allocated jtprod_residual!(nls, x, w, Jtv)
297297
end
298298

299299
if !(jac_op_residual in exclude) && nls_meta(nls).jprod_residual_available && nls_meta(nls).jtprod_residual_available
300-
x = get_x0(nlp)
300+
x = get_x0(nls)
301301
Jtv = similar(x)
302-
Jv = Vector{eltype(x)}(undef, get_nequ(nlp))
302+
Jv = Vector{eltype(x)}(undef, get_nequ(nls))
303303

304304
v = copy(x)
305-
w = zeros(eltype(x), get_nequ(nlp))
306-
J = jac_op_residual!(nlp, x, Jv, Jtv)
305+
w = zeros(eltype(x), get_nequ(nls))
306+
J = jac_op_residual!(nls, x, Jv, Jtv)
307307
mul!(Jv, J, v)
308-
nlp_allocations[:jac_op_residual_prod!] = @allocated mul!(Jv, J, v)
308+
nls_allocations[:jac_op_residual_prod!] = @allocated mul!(Jv, J, v)
309309
Jt = J'
310310
mul!(Jtv, Jt, w)
311-
nlp_allocations[:jac_op_residual_transpose_prod!] = @allocated mul!(Jtv, Jt, w)
311+
nls_allocations[:jac_op_residual_transpose_prod!] = @allocated mul!(Jtv, Jt, w)
312312
end
313313

314314
if !(hess_residual in exclude) && nls_meta(nls).hess_residual_available
315-
rows = Vector{Int}(undef, nlp.nls_meta.nnzh)
316-
cols = Vector{Int}(undef, nlp.nls_meta.nnzh)
317-
hess_structure_residual!(nlp, rows, cols)
318-
nlp_allocations[:hess_structure_residual!] =
319-
@allocated hess_structure_residual!(nlp, rows, cols)
320-
x = get_x0(nlp)
321-
v = ones(eltype(x), get_nequ(nlp))
322-
vals = Vector{eltype(x)}(undef, nlp.nls_meta.nnzh)
323-
hess_coord_residual!(nlp, x, v, vals)
324-
nlp_allocations[:hess_coord_residual!] = @allocated hess_coord_residual!(nlp, x, v, vals)
315+
rows = Vector{Int}(undef, nls.nls_meta.nnzh)
316+
cols = Vector{Int}(undef, nls.nls_meta.nnzh)
317+
hess_structure_residual!(nls, rows, cols)
318+
nls_allocations[:hess_structure_residual!] =
319+
@allocated hess_structure_residual!(nls, rows, cols)
320+
x = get_x0(nls)
321+
v = ones(eltype(x), get_nequ(nls))
322+
vals = Vector{eltype(x)}(undef, nls.nls_meta.nnzh)
323+
hess_coord_residual!(nls, x, v, vals)
324+
nls_allocations[:hess_coord_residual!] = @allocated hess_coord_residual!(nls, x, v, vals)
325325
end
326326

327-
for i = 1:get_nequ(nlp)
327+
for i = 1:get_nequ(nls)
328328
if !(hprod_residual in exclude) && nls_meta(nls).hprod_residual_available
329-
x = get_x0(nlp)
329+
x = get_x0(nls)
330330
v = copy(x)
331331
Hv = similar(x)
332-
hprod_residual!(nlp, x, i, v, Hv)
333-
nlp_allocations[:hprod_residual!] = @allocated hprod_residual!(nlp, x, i, v, Hv)
332+
hprod_residual!(nls, x, i, v, Hv)
333+
nls_allocations[:hprod_residual!] = @allocated hprod_residual!(nls, x, i, v, Hv)
334334
end
335335
if !(hess_op_residual in exclude) && nls_meta(nls).jprod_residual_available
336-
x = get_x0(nlp)
336+
x = get_x0(nls)
337337
Hv = similar(x)
338338
v = copy(x)
339-
H = hess_op_residual!(nlp, x, i, Hv)
339+
H = hess_op_residual!(nls, x, i, Hv)
340340
mul!(Hv, H, v)
341-
nlp_allocations[:hess_op_residual_prod!] = @allocated mul!(Hv, H, v)
341+
nls_allocations[:hess_op_residual_prod!] = @allocated mul!(Hv, H, v)
342342
end
343343
end
344-
return nlp_allocations
344+
return nls_allocations
345345
end
346346

347347
function NLPModels.histline(s::String, v::Integer, maxv::Integer)

0 commit comments

Comments
 (0)