Skip to content

Commit

Permalink
improve efficiency of caratheodory
Browse files Browse the repository at this point in the history
  • Loading branch information
jlchan committed May 10, 2024
1 parent 97e81b5 commit d2d26c9
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/physical_frame_basis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,25 +176,23 @@ function caratheodory_pruning_qr(V, w_in)
inds = collect(1:M)
m = M-N
Q, _ = qr(V)
Q = copy(Q)
for _ in 1:m
kvec = Q[:,end]
kvec = view(Q, :, size(Q, 2))

# for subtracting the kernel vector
idp = findall(@. kvec > 0)
alphap, k0p = findmin(w[inds[idp]] ./ kvec[idp])
alphap, k0p = findmin(view(w, inds[idp]) ./ view(kvec, idp))
k0p = idp[k0p]

# for adding the kernel vector
idn = findall(@. kvec < 0);
alphan, k0n = findmax(w[inds[idn]] ./ kvec[idn])
k0n = idn[k0n];
idn = findall(@. kvec < 0)
alphan, k0n = findmax(view(w, inds[idn]) ./ view(kvec, idn))
k0n = idn[k0n]

alpha, k0 = abs(alphan) < abs(alphap) ? (alphan, k0n) : (alphap, k0p)
w[inds] = w[inds] - alpha * kvec
@. w[inds] = w[inds] - alpha * kvec
deleteat!(inds, k0)
Q, _ = qr(V[inds, :])
Q = copy(Q)
end
return w, inds
end

0 comments on commit d2d26c9

Please sign in to comment.