Skip to content

Commit 6f45a6c

Browse files
authored
Merge pull request #25 from OptimalTransportNetworks/development
Minors: adding inbounds to speed up loop.
2 parents eaf05f5 + 41c3b3e commit 6f45a6c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/models/solve_allocation_by_duality_cgc.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function hessian_duality_cgc(
166166
ind = 0
167167

168168
# https://stackoverflow.com/questions/38901275/inbounds-propagation-rules-in-julia
169-
for (jdnd, jn) in zip(hess_str[1], hess_str[2])
169+
@inbounds for (jdnd, jn) in zip(hess_str[1], hess_str[2])
170170
ind += 1
171171
# First get the indices of the element and the respective derivative
172172
j = (jn-1) % J + 1
@@ -204,7 +204,7 @@ function hessian_duality_cgc(
204204
term += T * (((1+beta) * KPprimeAB1 + cons2 * KPABprime1) * G + Gprime) # T'G + TG'
205205
elseif jd == k
206206
term += Qjkn[j, k, n] * (KPAprimeB1 - KPABprime1) # Derivative of Qjkn
207-
term -= T * cons2 * KPABprime1 * G # Old T'G: second part [B'(k) has opposite sign]
207+
term -= T * cons2 * KPABprime1 * G # T'G: second part [B'(k) has opposite sign]
208208
end
209209
end
210210
if Qjkn[k, j, n] > 0 # Flows in the direction of j
@@ -213,9 +213,9 @@ function hessian_duality_cgc(
213213
KPAprimeB1 = nd == n ? n1dnum1 / (Pjn[j, n] - Pjn[k, n]) : 0.0
214214
if jd == k
215215
KPprimeAB1 = m1dbeta * Pjn[k, nd]^(-sigma) * PCj[k]^(sigma-1)
216-
term -= Qjkn[k, j, n] * (KPprimeAB1 - KPAprimeB1 + KPABprime1) # Derivative of Qjkn
216+
term -= Qjkn[k, j, n] * (KPprimeAB1 - KPAprimeB1 + KPABprime1) # Derivative of Qkjn
217217
elseif jd == j
218-
term -= Qjkn[k, j, n] * (KPAprimeB1 - KPABprime1) # Derivative of Qjkn
218+
term -= Qjkn[k, j, n] * (KPAprimeB1 - KPABprime1) # Derivative of Qkjn
219219
end
220220
end
221221
end # End of k loop

0 commit comments

Comments
 (0)