Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigFloat QR leads to ERROR: cannot resize array with shared data #40108

Open
dlfivefifty opened this issue Mar 19, 2021 · 1 comment
Open

BigFloat QR leads to ERROR: cannot resize array with shared data #40108

dlfivefifty opened this issue Mar 19, 2021 · 1 comment
Labels
linear algebra Linear algebra

Comments

@dlfivefifty
Copy link
Contributor

This is a bit surprising:

julia> A = BigFloat.(randn(5,5)); b = BigFloat.(randn(5));

julia> resize!(qr(A) \ b, 3)
ERROR: cannot resize array with shared data
Stacktrace:
 [1] _deleteend!
   @ ./array.jl:893 [inlined]
 [2] resize!(a::Vector{BigFloat}, nl::Int64)
   @ Base ./array.jl:1109
 [3] top-level scope
   @ REPL[9]:1

I tried to debug, the culprit seems to be somewhere in the orthogonal lmul!:

function lmul!(adjA::Adjoint{<:Any,<:QRPackedQ}, B::AbstractVecOrMat)

But nothing stands out...

@MikaelSlevinsky
Copy link

A workaround is to copy the output

ulia> A = BigFloat.(randn(5,5)); b = BigFloat.(randn(5));

julia> resize!(copy(qr(A) \ b), 3)
3-element Array{BigFloat,1}:
 1.128343225039452563013632216725243690076281918797619929418640609900994969010822
 0.3046898873582031740087773316219913340227916402714182242361382185620764253197802
 0.9309977144595598360049286776484760070368732518629144855630406146909686632942985

I could be wrong, but I think this is because the output vector is shared with a temporary vector in the QR factorization (maybe a Householder reflector?) that doesn't get cleared before its use in the solve phase. Copying the output places a memory barrier between it and a temporary array. (Not saying this is ideal.)

Note that lu works fine (perhaps because it implements elementary row operations in-place, i.e. without any temporary storage.)

julia> resize!(lu(A) \ b, 3)
3-element Array{BigFloat,1}:
 1.128343225039452563013632216725243690076281918797619929418640609900994969010788
 0.3046898873582031740087773316219913340227916402714182242361382185620764253198018
 0.9309977144595598360049286776484760070368732518629144855630406146909686632942726

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear algebra Linear algebra
Projects
None yet
Development

No branches or pull requests

3 participants