Skip to content

Commit 64a39ae

Browse files
committed
Update allocs_model.jl
1 parent 98e33d5 commit 64a39ae

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

Project.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1111
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1212

1313
[compat]
14-
NLPModels = "0.21"
14+
LinearAlgebra = "1.10"
15+
NLPModels = "0.21.6"
1516
NLPModelsModifiers = "0.7"
16-
julia = "^1.6"
17+
Printf = "1.10"
18+
SparseArrays = "1.10"
19+
Test = "1.10"
20+
julia = "1.10"
1721

1822
[extras]
1923
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"

src/allocs_model.jl

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ function test_allocs_nlpmodels(nlp::AbstractNLPModel; linear_api = false, exclud
3030
)
3131

3232
test_obj_grad!(nlp_allocations, nlp, exclude)
33-
if !(hess in exclude)
33+
34+
if !(hess in exclude) && nlp.meta.hess_available
3435
rows = Vector{Int}(undef, nlp.meta.nnzh)
3536
cols = Vector{Int}(undef, nlp.meta.nnzh)
3637
hess_structure!(nlp, rows, cols)
@@ -45,7 +46,8 @@ function test_allocs_nlpmodels(nlp::AbstractNLPModel; linear_api = false, exclud
4546
nlp_allocations[:hess_lag_coord!] = @allocated hess_coord!(nlp, x, y, vals)
4647
end
4748
end
48-
if !(hprod in exclude)
49+
50+
if !(hprod in exclude)&& nlp.meta.hprod_available
4951
x = get_x0(nlp)
5052
v = copy(x)
5153
Hv = similar(x)
@@ -57,7 +59,8 @@ function test_allocs_nlpmodels(nlp::AbstractNLPModel; linear_api = false, exclud
5759
nlp_allocations[:hprod_lag!] = @allocated hprod!(nlp, x, y, v, Hv)
5860
end
5961
end
60-
if !(hess_op in exclude)
62+
63+
if !(hess_op in exclude) && nlp.meta.hprod_available
6164
x = get_x0(nlp)
6265
Hv = similar(x)
6366
v = copy(x)
@@ -78,7 +81,8 @@ function test_allocs_nlpmodels(nlp::AbstractNLPModel; linear_api = false, exclud
7881
cons!(nlp, x, c)
7982
nlp_allocations[:cons!] = @allocated cons!(nlp, x, c)
8083
end
81-
if get_ncon(nlp) > 0 && !(jac in exclude)
84+
85+
if get_ncon(nlp) > 0 && !(jac in exclude) && nlp.meta.jac_available
8286
rows = Vector{Int}(undef, nlp.meta.nnzj)
8387
cols = Vector{Int}(undef, nlp.meta.nnzj)
8488
jac_structure!(nlp, rows, cols)
@@ -88,21 +92,24 @@ function test_allocs_nlpmodels(nlp::AbstractNLPModel; linear_api = false, exclud
8892
jac_coord!(nlp, x, vals)
8993
nlp_allocations[:jac_coord!] = @allocated jac_coord!(nlp, x, vals)
9094
end
91-
if get_ncon(nlp) > 0 && !(jprod in exclude)
95+
96+
if get_ncon(nlp) > 0 && !(jprod in exclude) && nlp.meta.jprod_available
9297
x = get_x0(nlp)
9398
v = copy(x)
9499
Jv = Vector{eltype(x)}(undef, get_ncon(nlp))
95100
jprod!(nlp, x, v, Jv)
96101
nlp_allocations[:jprod!] = @allocated jprod!(nlp, x, v, Jv)
97102
end
98-
if get_ncon(nlp) > 0 && !(jtprod in exclude)
103+
104+
if get_ncon(nlp) > 0 && !(jtprod in exclude) && nlp.meta.jtprod_available
99105
x = get_x0(nlp)
100106
v = copy(get_y0(nlp))
101107
Jtv = similar(x)
102108
jtprod!(nlp, x, v, Jtv)
103109
nlp_allocations[:jtprod!] = @allocated jtprod!(nlp, x, v, Jtv)
104110
end
105-
if get_ncon(nlp) > 0 && !(jac_op in exclude)
111+
112+
if get_ncon(nlp) > 0 && !(jac_op in exclude) && nlp.meta.jprod_available && nlp.meta.jtprod_available
106113
x = get_x0(nlp)
107114
Jtv = similar(x)
108115
Jv = Vector{eltype(x)}(undef, get_ncon(nlp))
@@ -130,7 +137,8 @@ function test_allocs_nlpmodels(nlp::AbstractNLPModel; linear_api = false, exclud
130137
eval(fun)(nlp, x, c)
131138
nlp_allocations[fun] = @allocated eval(fun)(nlp, x, c)
132139
end
133-
if !(jac in exclude)
140+
141+
if !(jac in exclude) && nlp.meta.jac_available
134142
rows = Vector{Int}(undef, nnzj)
135143
cols = Vector{Int}(undef, nnzj)
136144
fun = type == :lin ? jac_lin_structure! : jac_nln_structure! # eval(fun) would allocate here
@@ -142,23 +150,26 @@ function test_allocs_nlpmodels(nlp::AbstractNLPModel; linear_api = false, exclud
142150
eval(fun)(nlp, x, vals)
143151
nlp_allocations[fun] = @allocated eval(fun)(nlp, x, vals)
144152
end
145-
if !(jprod in exclude)
153+
154+
if !(jprod in exclude) && nlp.meta.jprod_available
146155
x = get_x0(nlp)
147156
v = copy(x)
148157
Jv = Vector{eltype(x)}(undef, nn)
149158
fun = Symbol(:jprod_, type, :!)
150159
eval(fun)(nlp, x, v, Jv)
151160
nlp_allocations[fun] = @allocated eval(fun)(nlp, x, v, Jv)
152161
end
153-
if !(jtprod in exclude)
162+
163+
if !(jtprod in exclude) && nlp.meta.jtprod_available
154164
x = get_x0(nlp)
155165
v = copy(get_y0(nlp)[1:nn])
156166
Jtv = similar(x)
157167
fun = Symbol(:jtprod_, type, :!)
158168
eval(fun)(nlp, x, v, Jtv)
159169
nlp_allocations[fun] = @allocated eval(fun)(nlp, x, v, Jtv)
160170
end
161-
if !(jac_op in exclude)
171+
172+
if !(jac_op in exclude) && nlp.meta.jprod_available && nlp.meta.jtprod_available
162173
x = get_x0(nlp)
163174
Jtv = similar(x)
164175
Jv = Vector{eltype(x)}(undef, nn)
@@ -199,7 +210,8 @@ function test_obj_grad!(nlp_allocations, nlp::AbstractNLPModel, exclude)
199210
obj(nlp, x)
200211
nlp_allocations[:obj] = @allocated obj(nlp, x)
201212
end
202-
if !(grad in exclude)
213+
214+
if !(grad in exclude) && nlp.meta.grad_available
203215
x = get_x0(nlp)
204216
g = similar(x)
205217
grad!(nlp, x, g)
@@ -215,7 +227,8 @@ function test_obj_grad!(nlp_allocations, nls::AbstractNLSModel, exclude)
215227
obj(nls, x, Fx)
216228
nlp_allocations[:obj] = @allocated obj(nls, x, Fx)
217229
end
218-
if !(grad in exclude)
230+
231+
if !(grad in exclude) && nls_meta(nls).jtprod_residual_available
219232
x = get_x0(nls)
220233
Fx = Vector{eltype(x)}(undef, get_nequ(nls))
221234
g = similar(x)
@@ -255,7 +268,8 @@ function test_allocs_nlsmodels(nlp::AbstractNLSModel; exclude = [])
255268
residual!(nlp, x, Fx)
256269
nlp_allocations[:residual!] = @allocated residual!(nlp, x, Fx)
257270
end
258-
if !(jac_residual in exclude)
271+
272+
if !(jac_residual in exclude) && nls_meta(nls).jac_residual_available
259273
rows = Vector{Int}(undef, nlp.nls_meta.nnzj)
260274
cols = Vector{Int}(undef, nlp.nls_meta.nnzj)
261275
jac_structure_residual!(nlp, rows, cols)
@@ -265,21 +279,24 @@ function test_allocs_nlsmodels(nlp::AbstractNLSModel; exclude = [])
265279
jac_coord_residual!(nlp, x, vals)
266280
nlp_allocations[:jac_coord_residual!] = @allocated jac_coord_residual!(nlp, x, vals)
267281
end
268-
if !(jprod_residual in exclude)
282+
283+
if !(jprod_residual in exclude) && nls_meta(nls).jprod_residual_available
269284
x = get_x0(nlp)
270285
v = copy(x)
271286
Jv = Vector{eltype(x)}(undef, get_nequ(nlp))
272287
jprod_residual!(nlp, x, v, Jv)
273288
nlp_allocations[:jprod_residual!] = @allocated jprod_residual!(nlp, x, v, Jv)
274289
end
275-
if !(jtprod_residual in exclude)
290+
291+
if !(jtprod_residual in exclude) && nls_meta(nls).jtprod_residual_available
276292
x = get_x0(nlp)
277293
w = zeros(eltype(x), get_nequ(nlp))
278294
Jtv = similar(x)
279295
jtprod_residual!(nlp, x, w, Jtv)
280296
nlp_allocations[:jtprod_residual!] = @allocated jtprod_residual!(nlp, x, w, Jtv)
281297
end
282-
if !(jac_op_residual in exclude)
298+
299+
if !(jac_op_residual in exclude) && nls_meta(nls).jprod_residual_available && nls_meta(nls).jtprod_residual_available
283300
x = get_x0(nlp)
284301
Jtv = similar(x)
285302
Jv = Vector{eltype(x)}(undef, get_nequ(nlp))
@@ -293,7 +310,8 @@ function test_allocs_nlsmodels(nlp::AbstractNLSModel; exclude = [])
293310
mul!(Jtv, Jt, w)
294311
nlp_allocations[:jac_op_residual_transpose_prod!] = @allocated mul!(Jtv, Jt, w)
295312
end
296-
if !(hess_residual in exclude)
313+
314+
if !(hess_residual in exclude) && nls_meta(nls).hess_residual_available
297315
rows = Vector{Int}(undef, nlp.nls_meta.nnzh)
298316
cols = Vector{Int}(undef, nlp.nls_meta.nnzh)
299317
hess_structure_residual!(nlp, rows, cols)
@@ -305,15 +323,16 @@ function test_allocs_nlsmodels(nlp::AbstractNLSModel; exclude = [])
305323
hess_coord_residual!(nlp, x, v, vals)
306324
nlp_allocations[:hess_coord_residual!] = @allocated hess_coord_residual!(nlp, x, v, vals)
307325
end
326+
308327
for i = 1:get_nequ(nlp)
309-
if !(hprod_residual in exclude)
328+
if !(hprod_residual in exclude) && nls_meta(nls).hprod_residual_available
310329
x = get_x0(nlp)
311330
v = copy(x)
312331
Hv = similar(x)
313332
hprod_residual!(nlp, x, i, v, Hv)
314333
nlp_allocations[:hprod_residual!] = @allocated hprod_residual!(nlp, x, i, v, Hv)
315334
end
316-
if !(hess_op_residual in exclude)
335+
if !(hess_op_residual in exclude) && nls_meta(nls).jprod_residual_available
317336
x = get_x0(nlp)
318337
Hv = similar(x)
319338
v = copy(x)

0 commit comments

Comments
 (0)