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

Vector accidentally overwritten in one specialization of / #35071

Closed
daanhb opened this issue Mar 11, 2020 · 1 comment
Closed

Vector accidentally overwritten in one specialization of / #35071

daanhb opened this issue Mar 11, 2020 · 1 comment
Labels
domain:linear algebra Linear algebra kind:bug Indicates an unexpected problem or unintended behavior

Comments

@daanhb
Copy link
Contributor

daanhb commented Mar 11, 2020

Reviewing all occurrences of conversions to the abstract type AbstractArray in LinearAlgebra, I came across this corner-case issue:

julia> using LinearAlgebra

julia> l = lu(rand(3,3)); v = transpose(rand(3));

julia> v
1×3 Transpose{Float64,Array{Float64,1}}:
 0.303153  0.935216  0.228176

julia> v / adjoint(l)
1×3 Adjoint{Float64,Array{Float64,1}}:
 1.78182  -0.065159  0.00787519

julia> v
1×3 Transpose{Float64,Array{Float64,1}}:
 1.78182  -0.065159  0.00787519

The vector v here is accidentally overwritten. The offending line is this one, where in the statement convert(AbstractVector{T}, conj(trA.parent)) neither conj nor the conversion is guaranteed to actually copy the data in all cases. There is a similar issue three lines below it (with equally exotic arguments).

My code review was motivated by #34995 and I'm currently attempting to fix both issues.

@daanhb
Copy link
Contributor Author

daanhb commented May 13, 2021

Meanwhile this issue has been fixed:

julia> using LinearAlgebra

julia> l = lu(rand(3,3)); v = transpose(rand(3));

julia> v
1×3 transpose(::Vector{Float64}) with eltype Float64:
 0.14045  0.85708  0.644903

julia> v / adjoint(l)
1×3 adjoint(::Vector{Float64}) with eltype Float64:
 0.128085  1.384  -0.657738

julia> v
1×3 transpose(::Vector{Float64}) with eltype Float64:
 0.14045  0.85708  0.644903

The offending line that said convert(...) now uses copy_oftype in lu.jl, compare this line to the new and improved implementation. It was fixed by #36657.

So I'm closing this issue.

@daanhb daanhb closed this as completed May 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:linear algebra Linear algebra kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants