Skip to content

Commit 7864819

Browse files
committed
try @eval
1 parent 9598598 commit 7864819

File tree

2 files changed

+115
-135
lines changed

2 files changed

+115
-135
lines changed

src/nlp/batch/api.jl

Lines changed: 74 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,82 @@
11
export AbstractBatchNLPModel
2-
export batch_obj, batch_grad, batch_grad!, batch_objgrad, batch_objgrad!, batch_objcons, batch_objcons!
3-
export batch_cons, batch_cons!, batch_cons_lin, batch_cons_lin!, batch_cons_nln, batch_cons_nln!
4-
export batch_jth_con, batch_jth_congrad, batch_jth_congrad!, batch_jth_sparse_congrad
5-
export batch_jac_structure!, batch_jac_structure, batch_jac_coord!, batch_jac_coord
6-
export batch_jac, batch_jprod, batch_jprod!, batch_jtprod, batch_jtprod!, batch_jac_op, batch_jac_op!
7-
export batch_jac_lin_structure!, batch_jac_lin_structure, batch_jac_lin_coord!, batch_jac_lin_coord
8-
export batch_jac_lin, batch_jprod_lin, batch_jprod_lin!, batch_jtprod_lin, batch_jtprod_lin!, batch_jac_lin_op, batch_jac_lin_op!
9-
export batch_jac_nln_structure!, batch_jac_nln_structure, batch_jac_nln_coord!, batch_jac_nln_coord
10-
export batch_jac_nln, batch_jprod_nln, batch_jprod_nln!, batch_jtprod_nln, batch_jtprod_nln!, batch_jac_nln_op, batch_jac_nln_op!
11-
export batch_jth_hess_coord, batch_jth_hess_coord!, batch_jth_hess
12-
export batch_jth_hprod, batch_jth_hprod!, batch_ghjvprod, batch_ghjvprod!
13-
export batch_hess_structure!, batch_hess_structure, batch_hess_coord!, batch_hess_coord
14-
export batch_hess, batch_hprod, batch_hprod!, batch_hess_op, batch_hess_op!
15-
export batch_varscale, batch_lagscale, batch_conscale
162

173
abstract type AbstractBatchNLPModel end
184

195
function NLPModels.increment!(bnlp::AbstractBatchNLPModel, fun::Symbol)
206
NLPModels.increment!(bnlp, Val(fun))
217
end
228

23-
function batch_obj end
24-
function batch_grad end
25-
function batch_grad! end
26-
function batch_objgrad end
27-
function batch_objgrad! end
28-
function batch_objcons end
29-
function batch_objcons! end
30-
function batch_cons end
31-
function batch_cons! end
32-
function batch_cons_lin end
33-
function batch_cons_lin! end
34-
function batch_cons_nln end
35-
function batch_cons_nln! end
36-
function batch_jth_con end
37-
function batch_jth_congrad end
38-
function batch_jth_congrad! end
39-
function batch_jth_sparse_congrad end
40-
function batch_jac_structure! end
41-
function batch_jac_structure end
42-
function batch_jac_coord! end
43-
function batch_jac_coord end
44-
function batch_jac end
45-
function batch_jprod end
46-
function batch_jprod! end
47-
function batch_jtprod end
48-
function batch_jtprod! end
49-
function batch_jac_op end
50-
function batch_jac_op! end
51-
function batch_jac_lin_structure! end
52-
function batch_jac_lin_structure end
53-
function batch_jac_lin_coord! end
54-
function batch_jac_lin_coord end
55-
function batch_jac_lin end
56-
function batch_jprod_lin end
57-
function batch_jprod_lin! end
58-
function batch_jtprod_lin end
59-
function batch_jtprod_lin! end
60-
function batch_jac_lin_op end
61-
function batch_jac_lin_op! end
62-
function batch_jac_nln_structure! end
63-
function batch_jac_nln_structure end
64-
function batch_jac_nln_coord! end
65-
function batch_jac_nln_coord end
66-
function batch_jac_nln end
67-
function batch_jprod_nln end
68-
function batch_jprod_nln! end
69-
function batch_jtprod_nln end
70-
function batch_jtprod_nln! end
71-
function batch_jac_nln_op end
72-
function batch_jac_nln_op! end
73-
function batch_jth_hess_coord end
74-
function batch_jth_hess_coord! end
75-
function batch_jth_hess end
76-
function batch_jth_hprod end
77-
function batch_jth_hprod! end
78-
function batch_ghjvprod end
79-
function batch_ghjvprod! end
80-
function batch_hess_structure! end
81-
function batch_hess_structure end
82-
function batch_hess_coord! end
83-
function batch_hess_coord end
84-
function batch_hess end
85-
function batch_hprod end
86-
function batch_hprod! end
87-
function batch_hess_op end
88-
function batch_hess_op! end
89-
function batch_varscale end
90-
function batch_lagscale end
91-
function batch_conscale end
9+
for fun in (
10+
:batch_obj,
11+
:batch_grad,
12+
:batch_grad!,
13+
:batch_objgrad,
14+
:batch_objgrad!,
15+
:batch_objcons,
16+
:batch_objcons!,
17+
:batch_cons,
18+
:batch_cons!,
19+
:batch_cons_lin,
20+
:batch_cons_lin!,
21+
:batch_cons_nln,
22+
:batch_cons_nln!,
23+
:batch_jth_con,
24+
:batch_jth_congrad,
25+
:batch_jth_congrad!,
26+
:batch_jth_sparse_congrad,
27+
:batch_jac_structure!,
28+
:batch_jac_structure,
29+
:batch_jac_coord!,
30+
:batch_jac_coord,
31+
:batch_jac,
32+
:batch_jprod,
33+
:batch_jprod!,
34+
:batch_jtprod,
35+
:batch_jtprod!,
36+
:batch_jac_op,
37+
:batch_jac_op!,
38+
:batch_jac_lin_structure!,
39+
:batch_jac_lin_structure,
40+
:batch_jac_lin_coord!,
41+
:batch_jac_lin_coord,
42+
:batch_jac_lin,
43+
:batch_jprod_lin,
44+
:batch_jprod_lin!,
45+
:batch_jtprod_lin,
46+
:batch_jtprod_lin!,
47+
:batch_jac_lin_op,
48+
:batch_jac_lin_op!,
49+
:batch_jac_nln_structure!,
50+
:batch_jac_nln_structure,
51+
:batch_jac_nln_coord!,
52+
:batch_jac_nln_coord,
53+
:batch_jac_nln,
54+
:batch_jprod_nln,
55+
:batch_jprod_nln!,
56+
:batch_jtprod_nln,
57+
:batch_jtprod_nln!,
58+
:batch_jac_nln_op,
59+
:batch_jac_nln_op!,
60+
:batch_jth_hess_coord,
61+
:batch_jth_hess_coord!,
62+
:batch_jth_hess,
63+
:batch_jth_hprod,
64+
:batch_jth_hprod!,
65+
:batch_ghjvprod,
66+
:batch_ghjvprod!,
67+
:batch_hess_structure!,
68+
:batch_hess_structure,
69+
:batch_hess_coord!,
70+
:batch_hess_coord,
71+
:batch_hess,
72+
:batch_hprod,
73+
:batch_hprod!,
74+
:batch_hess_op,
75+
:batch_hess_op!,
76+
:batch_varscale,
77+
:batch_lagscale,
78+
:batch_conscale,
79+
)
80+
@eval export $fun
81+
@eval function $fun end
82+
end

src/nlp/batch/foreach.jl

Lines changed: 41 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -100,58 +100,47 @@ for fun in fieldnames(Counters)
100100
bnlp.counters.$fun += 1
101101
end
102102
end
103-
104-
105-
batch_jac_structure(bnlp::ForEachBatchNLPModel) =
106-
_batch_map(jac_structure, bnlp)
107-
batch_jac_lin_structure(bnlp::ForEachBatchNLPModel) =
108-
_batch_map(jac_lin_structure, bnlp)
109-
batch_jac_nln_structure(bnlp::ForEachBatchNLPModel) =
110-
_batch_map(jac_nln_structure, bnlp)
111-
batch_hess_structure(bnlp::ForEachBatchNLPModel) =
112-
_batch_map(hess_structure, bnlp)
113-
batch_obj(bnlp::ForEachBatchNLPModel, xs) =
114-
_batch_map(obj, bnlp, xs)
115-
batch_grad(bnlp::ForEachBatchNLPModel, xs) =
116-
_batch_map(grad, bnlp, xs)
117-
batch_cons(bnlp::ForEachBatchNLPModel, xs) =
118-
_batch_map(cons, bnlp, xs)
119-
batch_cons_lin(bnlp::ForEachBatchNLPModel, xs) =
120-
_batch_map(cons_lin, bnlp, xs)
121-
batch_cons_nln(bnlp::ForEachBatchNLPModel, xs) =
122-
_batch_map(cons_nln, bnlp, xs)
123-
batch_jac(bnlp::ForEachBatchNLPModel, xs) =
124-
_batch_map(jac, bnlp, xs)
125-
batch_jac_lin(bnlp::ForEachBatchNLPModel, xs) =
126-
_batch_map(jac_lin, bnlp, xs)
127-
batch_jac_nln(bnlp::ForEachBatchNLPModel, xs) =
128-
_batch_map(jac_nln, bnlp, xs)
129-
batch_jac_lin_coord(bnlp::ForEachBatchNLPModel, xs) =
130-
_batch_map(jac_lin_coord, bnlp, xs)
131-
batch_jac_coord(bnlp::ForEachBatchNLPModel, xs) =
132-
_batch_map(jac_coord, bnlp, xs)
133-
batch_jac_nln_coord(bnlp::ForEachBatchNLPModel, xs) =
134-
_batch_map(jac_nln_coord, bnlp, xs)
135-
batch_varscale(bnlp::ForEachBatchNLPModel) =
136-
_batch_map(varscale, bnlp)
137-
batch_lagscale(bnlp::ForEachBatchNLPModel) =
138-
_batch_map(lagscale, bnlp)
139-
batch_conscale(bnlp::ForEachBatchNLPModel) =
140-
_batch_map(conscale, bnlp)
141-
batch_jprod(bnlp::ForEachBatchNLPModel, xs, vs) =
142-
_batch_map(jprod, bnlp, xs, vs)
143-
batch_jtprod(bnlp::ForEachBatchNLPModel, xs, vs) =
144-
_batch_map(jtprod, bnlp, xs, vs)
145-
batch_jprod_nln(bnlp::ForEachBatchNLPModel, xs, vs) =
146-
_batch_map(jprod_nln, bnlp, xs, vs)
147-
batch_jtprod_nln(bnlp::ForEachBatchNLPModel, xs, vs) =
148-
_batch_map(jtprod_nln, bnlp, xs, vs)
149-
batch_jprod_lin(bnlp::ForEachBatchNLPModel, xs, vs) =
150-
_batch_map(jprod_lin, bnlp, xs, vs)
151-
batch_jtprod_lin(bnlp::ForEachBatchNLPModel, xs, vs) =
152-
_batch_map(jtprod_lin, bnlp, xs, vs)
153-
batch_ghjvprod(bnlp::ForEachBatchNLPModel, xs, gs, vs) =
154-
_batch_map(ghjvprod, bnlp, xs, gs, vs)
103+
for (batch_fun, fun) in (
104+
(:batch_jac_structure, :jac_structure),
105+
(:batch_jac_lin_structure, :jac_lin_structure),
106+
(:batch_jac_nln_structure, :jac_nln_structure),
107+
(:batch_hess_structure, :hess_structure),
108+
(:batch_varscale, :varscale),
109+
(:batch_lagscale, :lagscale),
110+
(:batch_conscale, :conscale),
111+
)
112+
@eval $batch_fun(bnlp::ForEachBatchNLPModel) = _batch_map($fun, bnlp)
113+
end
114+
for (batch_fun, fun) in (
115+
(:batch_obj, :obj),
116+
(:batch_grad, :grad),
117+
(:batch_cons, :cons),
118+
(:batch_cons_lin, :cons_lin),
119+
(:batch_cons_nln, :cons_nln),
120+
(:batch_jac, :jac),
121+
(:batch_jac_lin, :jac_lin),
122+
(:batch_jac_nln, :jac_nln),
123+
(:batch_jac_lin_coord, :jac_lin_coord),
124+
(:batch_jac_coord, :jac_coord),
125+
(:batch_jac_nln_coord, :jac_nln_coord),
126+
)
127+
@eval $batch_fun(bnlp::ForEachBatchNLPModel, x) = _batch_map($fun, bnlp, x)
128+
end
129+
for (batch_fun, fun) in (
130+
(:batch_jprod, :jprod),
131+
(:batch_jtprod, :jtprod),
132+
(:batch_jprod_nln, :jprod_nln),
133+
(:batch_jtprod_nln, :jtprod_nln),
134+
(:batch_jprod_lin, :jprod_lin),
135+
(:batch_jtprod_lin, :jtprod_lin),
136+
)
137+
@eval $batch_fun(bnlp::ForEachBatchNLPModel, x, y) = _batch_map($fun, bnlp, x, y)
138+
end
139+
for (batch_fun, fun) in (
140+
(:batch_ghjvprod, :ghjvprod),
141+
)
142+
@eval $batch_fun(bnlp::ForEachBatchNLPModel, x, y, z) = _batch_map($fun, bnlp, x, y, z)
143+
end
155144

156145
batch_jac_structure!(bnlp::ForEachBatchNLPModel, rowss, colss) =
157146
_batch_map!(jac_structure!, bnlp, rowss, colss)

0 commit comments

Comments
 (0)