-
Notifications
You must be signed in to change notification settings - Fork 7
Closed
Description
Hi,
I encountered an unexpected bug in my tests after replacing qrdelcol with qrdelcol!, and I can't figure out why it's happening. It seems like qrdelcol! doesn't return the correct R matrix. I'll share the exact matrices in a JLD2 file and a script that reproduces the issue. I would greatly appreciate a prompt review of this problem.
using QRupdate, JLD2, LinearAlgebra, InvertedIndices
@load "matrices.jld2" S_array R_array
S = S_array
R = R_array
## doing the following slicing to mimic how qrdelcol saves matrices
S_ = S_array[:,1:5]
R_ = R_array[1:5,1:5]
qrdelcol!(S, R, 3) #inplace
S_ = S_[:, Not(3)]
R_ = qrdelcol(R_, 3)
norm(S[:,1:4]-S_) # this gives back 0
norm(R[1:4,1:4] - R_) #!!!
norm( R_'*R_ - S_'*S_ ) # seems right
norm( R'*R - S'*S ) # weird
I think this is the problematic part:
# Shift columns. This is apparently faster than copying views.
for j in (k+1):n, i in 1:m
@inbounds R[i,j-1] = R[i, j]
@inbounds A[i,j-1] = A[i, j]
end
Changing it to
for j in (k+1):n
@inbounds for i in 1:m
R[i, j-1] = R[i, j]
A[i, j-1] = A[i, j]
end
end
solves the issue. I'm not entirely sure but I think the first version kinda overwrites matrix entries during the shifting, but it's more memory/cache efficient obviously.
Metadata
Metadata
Assignees
Labels
No labels