@@ -100,6 +100,13 @@ function bpdual(
100100 # ------------------------------------------------------------------
101101 m, n = size (A)
102102
103+
104+ work = rand (n)
105+ work2 = rand (n)
106+ work3 = rand (n)
107+ work4 = rand (n)
108+ work5 = rand (m)
109+
103110 tracer = ASPTracer (
104111 Int[], # iteration
105112 Float64[], # lambda
@@ -110,8 +117,8 @@ function bpdual(
110117 active = Vector {Int} ([])
111118 state = Vector {Int} (zeros (Int, n))
112119 y = Vector {Float64} (zeros (Float64, m))
113- S = Matrix {Float64} (zeros (Float64, m, 0 ))
114- R = Matrix {Float64} (zeros (Float64, 0 , 0 ))
120+ S = Matrix {Float64} (zeros (Float64, m, n ))
121+ R = Matrix {Float64} (zeros (Float64, n, n ))
115122 end
116123
117124 if homotopy
@@ -171,6 +178,8 @@ function bpdual(
171178 numtrim = 0
172179 nprodA = 0
173180 nprodAt = 0
181+ cur_r_size = 0
182+
174183
175184 # ------------------------------------------------------------------
176185 # Cold/warm-start initialization.
@@ -186,7 +195,7 @@ function bpdual(
186195 end
187196 else
188197 g = b - λ* y # Compute steepest-descent dir
189- triminf (active, state, S, R, bl, bu, g)
198+ active, state, S, R = triminf! (active, state, S, R, bl, bu, g)
190199 nact = length (active)
191200 x = zeros (nact)
192201 y = restorefeas (y, active, state, S, R, bl, bu)
@@ -211,25 +220,25 @@ function bpdual(
211220 sL, sU = infeasibilities (bl, bu, z)
212221 g = b - λ* y # Steepest-descent direction
213222
214- if isempty (R )
223+ if isempty (( @view R[ 1 : cur_r_size, 1 : cur_r_size]) )
215224 condS = 1
216225 else
217- rmin = minimum (diag (R ))
218- rmax = maximum (diag (R ))
226+ rmin = minimum (diag (( @view R[ 1 : cur_r_size, 1 : cur_r_size]) ))
227+ rmax = maximum (diag (( @view R[ 1 : cur_r_size, 1 : cur_r_size]) ))
219228 condS = rmax / rmin
220229 end
221230
222231 if condS > 1e+10
223232 eFlag = :EXIT_SINGULAR_LS
224233 # Pad x with enough zeros to make it compatible with S.
225- npad = size (S , 2 ) - size (x, 1 )
234+ npad = size (( @view S[:, 1 : cur_r_size]) , 2 ) - size (x, 1 )
226235 x = [x; zeros (npad)]
227236 else
228- dx, dy = newtonstep (S, R , g, x, λ)
237+ dx, dy = newtonstep (( @view S[:, 1 : cur_r_size]), ( @view R[ 1 : cur_r_size, 1 : cur_r_size]) , g, x, λ)
229238 x .+ = dx
230239 end
231240
232- r = b - S* x
241+ r = b - S[:, 1 : cur_r_size] * x
233242
234243 # Print to log.
235244 yNorm = norm (y, 2 )
@@ -273,7 +282,7 @@ function bpdual(
273282 @info " \n Optimal solution found. Trimming multipliers..."
274283 end
275284 g = b - λin* y
276- trimx (x, S, R , active, state, g, b, λ, feaTol, optTol, loglevel)
285+ trimx (x, ( @view S[:, 1 : cur_r_size]), ( @view R[ 1 : cur_r_size, 1 : cur_r_size]) , active, state, g, b, λ, feaTol, optTol, loglevel)
277286 numtrim = nact - length (active)
278287 nact = length (active)
279288 end
@@ -288,7 +297,7 @@ function bpdual(
288297 p = q = 0
289298
290299 if homotopy
291- x, dy, dz, step, λ, p = htpynewlam (active, state, A, R, S , x, y, sL, sU, λ, lamFinal)
300+ x, dy, dz, step, λ, p = htpynewlam (active, state, A, ( @view R[ 1 : cur_r_size, 1 : cur_r_size]), ( @view S[:, 1 : cur_r_size]) , x, y, sL, sU, λ, lamFinal)
292301 nprodAt += 1
293302 else
294303 if norm (dy, Inf ) < eps ()
@@ -339,8 +348,9 @@ function bpdual(
339348 a = A * zerovec
340349 nprodA += 1
341350 zerovec[p] = 0
342- R = qraddcol (S, R, a)
343- S = [S a]
351+ qraddcol! (S, R, a, cur_r_size, work, work2, work3, work4, work5) # Update R
352+ cur_r_size += 1
353+ # S = [S a]
344354 push! (active, p)
345355 push! (x, 0 )
346356 else
@@ -358,10 +368,12 @@ function bpdual(
358368 _, qa = findmax (abs .(x .* dropa))
359369 q = active[qa]
360370 state[q] = 0
361- S = S[:, 1 : nact .!= qa]
371+ # S = S[:, 1:nact .!= qa]
362372 deleteat! (active, qa)
363373 deleteat! (x, qa)
364- R = qrdelcol (R, qa)
374+ # R = qrdelcol(R, qa)
375+ qrdelcol! (S, R, qa)
376+ cur_r_size -= 1
365377 else
366378 eFlag = :EXIT_OPTIMAL
367379 end
@@ -390,4 +402,4 @@ function bpdual(
390402 @info " Solution time (sec): $tottime "
391403 end
392404 return tracer
393- end
405+ end
0 commit comments