Skip to content

Commit df4a7dc

Browse files
mtanneaumtanneau3
andauthored
More compact M, N formation (#313)
Co-authored-by: mtanneau3 <[email protected]>
1 parent 3b29d7f commit df4a7dc

File tree

1 file changed

+15
-30
lines changed

1 file changed

+15
-30
lines changed

src/NonLinearProgram/nlp_utilities.jl

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -359,38 +359,23 @@ function _build_sensitivity_matrices(
359359
# Based on the implicit function diferentiation method used in sIpopt to derive sensitivities
360360
# Ref: sIPOPT paper https://optimization-online.org/wp-content/uploads/2011/04/3008.pdf.
361361
# M = [
362-
# [W A' -I I];
363-
# [A 0 0 0];
364-
# [V_L 0 (X - X_L) 0]
365-
# [V_U 0 0 0 (X_U - X)]
362+
# [W A' -I I ];
363+
# [A 0 0 0 ];
364+
# [V_L 0 (X-X_L) 0 ]
365+
# [V_U 0 0 (X_U - X)]
366366
# ]
367-
len_w = num_vars + num_ineq
368-
M = spzeros(
369-
len_w + num_cons + num_low + num_up,
370-
len_w + num_cons + num_low + num_up,
371-
)
372-
373-
M[1:len_w, 1:len_w] = W
374-
M[1:len_w, (len_w+1):(len_w+num_cons)] = A'
375-
M[(len_w+1):(len_w+num_cons), 1:len_w] = A
376-
M[1:len_w, (len_w+num_cons+1):(len_w+num_cons+num_low)] = I_L
377-
M[(len_w+num_cons+1):(len_w+num_cons+num_low), 1:len_w] = V_L
378-
M[
379-
(len_w+num_cons+1):(len_w+num_cons+num_low),
380-
(len_w+num_cons+1):(len_w+num_cons+num_low),
381-
] = X_lb
382-
M[(len_w+num_cons+num_low+1):(len_w+num_cons+num_low+num_up), 1:len_w] = V_U
383-
M[
384-
(len_w+num_cons+num_low+1):(len_w+num_cons+num_low+num_up),
385-
(len_w+num_cons+num_low+1):(len_w+num_cons+num_low+num_up),
386-
] = X_ub
387-
M[1:len_w, (len_w+num_cons+num_low+1):end] = I_U
388-
367+
M = [
368+
W A' I_L I_U;
369+
A spzeros(num_cons, num_cons) spzeros(num_cons, num_low) spzeros(num_cons, num_up);
370+
V_L spzeros(num_low, num_cons) X_lb spzeros(num_low, num_up);
371+
V_U spzeros(num_up, num_cons) spzeros(num_up, num_low) X_ub;
372+
]
389373
# N matrix
390-
# N = [∇ₓₚL ; ∇ₚC; zeros(num_low + num_up, num_parms)]
391-
N = spzeros(len_w + num_cons + num_low + num_up, num_parms)
392-
N[1:len_w, :] = ∇ₓₚL
393-
N[(len_w+1):(len_w+num_cons), :] = ∇ₚC
374+
N = [
375+
∇ₓₚL;
376+
∇ₚC;
377+
spzeros(num_low + num_up, num_parms);
378+
]
394379

395380
return M, N
396381
end

0 commit comments

Comments
 (0)